0

I am experiencing a weird behavior on my android application. When I open my application, I see my DashboardActivity, then I hit home button or back button and my application closes. This is ok. Then I receive a push message and with this push message I create a notification. The notification works fine, I click the notification and it opens my activity, using the code below:

Intent notificationIntent = new Intent(context, BookingOfferActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Bundle b = new Bundle();
b.putSerializable("booking", booking);
notificationIntent.putExtras(b);

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

Then I execute some task in this BookingOfferActivity activity and call the method finish() to make sure this activity will be finished no matter what. Then I open my application again, but instead of seeing the DashboardActivity I am still seeing BookingOfferActivity.

I have tried the solution proposed here:

Prevent new activity instance after clicking on notification

but it just doesnt work.

Is there a way to force my application to always open on the DashboardActivity?

Thanks

T

Community
  • 1
  • 1
Thiago
  • 5,152
  • 11
  • 35
  • 44

3 Answers3

0

i don't know exactly, but u can try to finish all activities in onStop() method. in onResume() method start your DashboardActivity.

Veaceslav Gaidarji
  • 4,261
  • 3
  • 38
  • 61
0

That is strange behaviour considering you are calling finish()

Try setting

android:noHistory="true"
android:launchMode="singleInstance"

in the manifest for the BookingOfferActivity

triggs
  • 5,890
  • 3
  • 32
  • 31
  • Hi @triggs, I just this what you said, it didnt work. After calling finish() on my BookingOfferActivity and opening my application again, the activity is still there. Thanks for trying to help me! – Thiago Dec 14 '11 at 22:55
  • very strange, perhaps you should edit your question with some code from your BookingOfferActivity, also try removing CLEAR_TOP from the notificationIntent – triggs Dec 14 '11 at 23:28
0

Try removing SINGLE_TOP from your intent. CLEAR_TOP should be all you want.

From the Android Developer documentation

FLAG_ACTIVITY_SINGLE_TOP -> If set, the activity will not be launched if it is already running at the top of the history stack.

Lionel Port
  • 3,492
  • 23
  • 26
  • Hi Lionel, still not working with your answer. I am still trying to figure out why this is happening. Thanks again – Thiago Dec 15 '11 at 12:37