My Android app is very big and complex. Therefor the app use much memory space and CPU. So when user click the "home" or "back" button on Android device, I hope that the app finish completely. Please someone help me. Appreciate that share sample code or link.
Asked
Active
Viewed 176 times
0
-
on you can release reference in onBackPressed() method of home activity – H Raval Mar 23 '16 at 13:20
1 Answers
0
You could call the finish();
method in any activity either after starting the next activity, or in onPause();
example:
After starting activity B from activity A
startActivity(new Intent(A.this, B.class));
finish();
and to make sure activity does not stay in the background when pressing Home button you could call finish();
inside your onPause();
@Override
protected void onPause(){
finish();
}

Bisho Adam
- 191
- 1
- 2
- 12
-
In my app used many activities. According your sample code, when start new activity from main activity the app would be finished. – Miguel A. Mar 23 '16 at 14:16
-
Not exactly, the finish(); only kills the activity, so if you call it from your MainActivity, the next activity will start but you won't be able to navigate back to your MainActivity, you could just NOT call it in the MainActivity if you want it to stay. – Bisho Adam Mar 23 '16 at 14:20