sarath
sarath

Reputation: 3201

Notification screen issue

I am working on an android application. In my app I am using nottification. I have two screens screen1 and screen2. Whenever notification came .If we click on the notification in will lead to screen2. Now my problem is if I am in screen2. One new notification came and click on the notification will open screen 2 .Then the click on the back button will display the screen2 again. Because click on the notification open screen2 infront of previous screen2. How can I overcome this issue?

Upvotes: 1

Views: 81

Answers (2)

Andro Selva
Andro Selva

Reputation: 54322

Add this Flag Value to your Notification Intent,

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_NEW_TASK);

This will ensure that if your called Activity is on Top of the Stack no new Instance of it will be created, instead it just helps you to move to that Activity.

Upvotes: 2

A. AMAIDI
A. AMAIDI

Reputation: 6849

you should just define your activity as single instance in your manifest file

 <activity android:name=".Screen2"
       android:launchMode="singleTask" />

using launchMode will prevent the activity from being launched several times.

Upvotes: 3

Related Questions