0

I have an activity which opens using alarm manager.There are some operations can be performed by user in it.On clicking a button ,activity finishes using finish().

My problem is that after being finished,user can still resume the activity using Home button and can repeat the operations that he had performed earlier. How can I stop this?

Please help.

I have used :

Intent i = new Intent(context, Alert.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(i);

to start the activity from on receive of alarm manager. and used in menifiest :

        android:configChanges="orientation|screenSize"
        android:excludeFromRecents="true"
        android:launchMode="singleTask"
        android:noHistory="true" 
Sar
  • 550
  • 4
  • 18
  • you dont want your task to be shown in recent apps. did i understand right ? – Ramesh Aug 12 '15 at 13:20
  • yes because user can resume the activity and user can repeat the operations. I cannot allow that. – Sar Aug 12 '15 at 13:23

2 Answers2

1

if your intention is to not show your activity triggerred from alarm in recent tasks list that comes up when we hit home button. you should set

android:excludeFromRecents="true" 

in your android manifest file in activity declaration.

But in case your activity is already inside recent apps this would not work. Then you will have to make it singleTask using

android:launchMode="singleTask"

so that your activity is always in single task and you close that task when you finish.

Ramesh
  • 1,287
  • 1
  • 9
  • 14
  • have you added both flags or only excludefromrecents. can you post activity tag in your androidManifest.xml – Ramesh Aug 12 '15 at 13:50
  • http://stackoverflow.com/questions/27633329/activity-excludefromrecents-not-working-on-android-5-0 check if this helps. which android version are you on?? – Ramesh Aug 12 '15 at 13:59
  • and I hope you tried this by removing all the previous tasks and freshly installing your application? It does work for me. – Ramesh Aug 12 '15 at 14:04
0

You can add the following tag to the Activity declaration in the manifest:

android:excludeFromRecents="true"
Emanuel Moecklin
  • 28,488
  • 11
  • 69
  • 85