I am developing an Android application with few views like A,B,C,D. Here D is my home activity. My navigation is like A->B->C->D. Once I reach Activity D, when I try to press back button, all previous activities (A,B,C) should close. I can’t start activity like finish called calling new activity. Please provide me a way to kill activity of my application.
Here I’ve used some code to finish all activities but did not get result.
ActivityManager manager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> list = manager.getRunningAppProcesses();
if(list != null)
{
for(int i=0;i<list.size();++i) {
if(getApplicationContext().getPackageName().matches(list.get(i).processName)) {
int pid = android.os.Process.getUidForName(getApplicationContext().getPackageName());
android.os.Process.killProcess(pid);
}
else {
debug.log("app not killed");
}
}
}
So please suggest me proper way to close all my activity at a time.
Thanks in advace
Thank you for all who respond for my question. Finally i got the solution for my issue. I resolved that by using the intent Intent.FLAG_ACTIVITY_CLEAR_TOP. Here is explanation for my scenario.
Assume i am in Activity D. My actual flow is A->B->C->D.i want to kill my previous activities A,B,C. I used to call my first activity A when i am going from Activity D.
So i added intent FLAG_ACTIVITY_CLEAR_TOP to call activity A. So the middle activities will cleared and will show only Activity A. And i am passing some flag value as intent extras to activity A. like this
and i am checking the bundle value in onCreate method of Activity A like
If the status value available and it is true then i am finishing the activity A also. So my problem is cleared and i am successfully finishing the all previous activities.
May be my explanation is not good but will work perfectly.