I am using Strict mode in one of my main activity in onCreate
method
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.penaltyDeath()
.build());
The Activity has 4 fragments and when i click on the notification of GCM then a new instance of my activity is getting created rather than resuming my activity which is giving error and shutting down my activity.
Here is the error:
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
here is the configuration for intent filter for TestActivity.
<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>
and Notification Builder
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());
So where should i need to change the code so that the notification will open in single instance?