googleads-adsense-examples
googleads-adsense-examples copied to clipboard
Adsense Quickstart App crashing on start
Solved the error that occurred when the app starts. App starts, then onCreate is called, then onNavigationItemSelected(..) is called, then refreshView() is called because at this point publisherAccountId is null, which then calls apiController.loadAccounts() which has an invalid credential name because no account name was ever set.
The app was trying to loadaccounts from null user.
Change in MainActivity:
- if ((apiController.getAccounts() == null) || (publisherAccountId == null)) {
-
status = AppStatus.GETTING_ACCOUNT_ID;
-
refreshView();
-
return true;
To:
- if ((apiController.getAccounts() == null) && (publisherAccountId == null)) {
-
chooseDeviceAccount();
-
return true;
- } else if ((apiController.getAccounts() == null) || (publisherAccountId == null)) {
-
status = AppStatus.GETTING_ACCOUNT_ID;
-
refreshView();
-
}return true;