Last few days i have noticed strange bahaviour in my push notifications.
After i receive a push notification i am able to click on it to open the app.
It works fine, till randomly, for some reason after clicking the push notification the app wants to open, but hangs completely. The result is a black stuck screen and an ANR. The app needs to be forced closed.
I spend hours to find the cause. I found one odd thing.
After i removed the google Ads activity entry from the manifest.xml everything seemed to be working. Except for ads of course.
now i remember that i have updated google play services to revision 14 a couple of weeks ago.
My manifest looks like this:
<activity
android:name="soccer.MainActivity"
android:label="@string/Voetbal" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
from the broadcast receiver in onreceive i have the following code
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra("matchid", matchid);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN){
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
} else{
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
intent.setData(Uri.parse("content://"+when));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
NotificationManager notificationManager =(NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
context.getApplicationContext())
.setWhen(when)
.setContentText(notificationContent)
.setContentTitle(notificationTitle)
.setSmallIcon(smalIcon)
.setAutoCancel(true)
.setTicker(notificationTitle)
//.setLargeIcon(largeIcon)
.setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_VIBRATE| Notification.DEFAULT_SOUND)
.setContentIntent(pendingIntent);
Notification notification=notificationBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
try {
notificationManager.notify(Integer.parseInt(matchid), notification);
;
} catch (NumberFormatException e) {
notificationManager.notify(0, notification);
}
I am absolutely sure that when i remove the google ads activity the problems are gone.
I have no clue whats going on. Could it be that android is trying to start the ads activity instead of the MainActivity. When the problem occurs "onCreate" is not called as well.
i dived into the traces.txt file which gets generated after an ANR. Its a huge file, but it starts with:
JNI: CheckJNI is off; workarounds are off; pins=0; globals=302 (plus 121 weak)
DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0)
"main" prio=5 tid=1 MONITOR
| group="main" sCount=1 dsCount=0 obj=0x41b3cca8 self=0x41b2b3c8
| sysTid=26971 nice=-6 sched=0/0 cgrp=apps handle=1074516308
| state=S schedstat=( 0 0 0 ) utm=302 stm=78 core=0
at aal.b(SourceFile:~287)
- waiting to lock <0x42a2af28> (a java.lang.Object) held by tid=16 (AdWorker #1)
at abm.f(SourceFile:33)
at xq.r(SourceFile:593)
at xq.b(SourceFile:168)
at ya.onTransact(SourceFile:59)
at android.os.Binder.transact(Binder.java:361)
at com.google.android.gms.internal.ac$a$a.destroy((null):-1)
←[7m--more--←[0m
at com.google.android.gms.ads.AdView.destroy((null):-1)
at soccer.ContainerFragmentMatchInfo.onDestroy(ContainerFragmentMatchInfo.java:93)
at android.support.v4.app.Fragment.performDestroy(Fragment.java:1720)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1056)
at android.support.v4.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1201)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:639)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:456)
at com.actionbarsherlock.app.SherlockFragmentActivity.onPostResume(SherlockFragmentActivity.java:68)
at android.app.Activity.performResume(Activity.java:5323)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
UPDATE::
if i remove the following code from my application everything seems to work again:
@Override
public void onPause() {
adView.pause();
super.onPause();
}
@Override
public void onResume() {
super.onResume();
adView.resume();
}
@Override
public void onDestroy() {
adView.destroy();
super.onDestroy();
}
i have no clue why. and i dont know what the impact is.