我在onCreate
方法
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.penaltyDeath()
.build());
活动有4个片段,当我点击GCM的通知时,我的活动的新实例正在创建,而不是恢复我的活动,这会导致错误并关闭我的活动。
这是错误:
com.test E/StrictMode: class com.test.activity.TestActivity; instances=2; limit=1
android.os.StrictMode$InstanceCountViolation: class com.test.activity.TestActivity; instances=2; limit=1
at android.os.StrictMode.setClassInstanceLimit(StrictMode.java:1)
com.test W/System.err: StrictMode VmPolicy violation with POLICY_DEATH; shutting down.
com.test D/Process: killProcess, pid=15352
com.test D/Process: android.os.StrictMode.onVmPolicyViolation:1686 android.os.StrictMode.decrementExpectedActivityCount:2098 android.app.ActivityThread.performDestroyActivity:4052
这是TestActivity的intent过滤器的配置。
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
和通知构建器
PendingIntent pendingIntent = PendingIntent.getActivity(this, REQ_CODE, intent,
PendingIntent.FLAG_ONE_SHOT);
notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setSmallIcon(getNotificationIcon())
.setContentTitle("GCM")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTF_ID, notificationBuilder.build());
那么我应该在哪里更改代码以便通知将在单个实例中打开?