ここ数日、プッシュ通知で奇妙な動作に気付きました。プッシュ通知を受け取った後、それをクリックしてアプリを開くことができます。アプリが開きたいプッシュ通知をクリックした後、何らかの理由でランダムになるまで正常に動作しますが、完全にハングします。その結果、黒いスタック画面と ANR が発生します。アプリを強制終了する必要があります。
原因を見つけるのに何時間も費やします。一つ変なことを見つけました。manifest.xml から Google 広告のアクティビティ エントリを削除した後、すべてが機能しているように見えました。もちろん、広告を除いて。数週間前に Google Play サービスをリビジョン 14 に更新したことを今思い出しました。
私のマニフェストは次のようになります。
<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" />
onreceiveのブロードキャストレシーバーから、次のコードがあります
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);
}
Google 広告のアクティビティを削除すると、問題がなくなると確信しています。何が起こっているのかわかりません。Android が MainActivity の代わりに広告アクティビティを開始しようとしている可能性があります。問題が発生すると、「onCreate」も呼び出されません。
ANR の後に生成される traces.txt ファイルに飛び込みました。巨大なファイルですが、次で始まります。
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)
アップデート::
アプリケーションから次のコードを削除すると、すべてが再び機能するように見えます:
@Override
public void onPause() {
adView.pause();
super.onPause();
}
@Override
public void onResume() {
super.onResume();
adView.resume();
}
@Override
public void onDestroy() {
adView.destroy();
super.onDestroy();
}
理由がわかりません。そして、私はその影響が何であるかを知りません。