Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between closing app via back button and clearing it from recents list?

My app uses a DefaultHttpClient to make network requests. On occasion (usually after resuming the app after a long period of time) the app will stop loading data and I need to clear it from the recent apps list before it loads content again.

My question is, what's the difference between: - Closing an app by tapping the back button - Clearing the app from the recent app list

When my app stops loading content, exiting via the back button and reopening does not fix the problem. Only killing the app by clearing it from the recent app list works.

Is there a way to "kill" the app when a user exits with the back button?

Thanks

like image 951
Michael J Avatar asked Aug 10 '16 19:08

Michael J


People also ask

How do I close apps on back button?

In order to check when the 'BACK' button is pressed, use onBackPressed() method from the Android library. Next, perform a check to see if the 'BACK' button is pressed again within 2 seconds and will close the app if it is so.

How do I completely close an app on Android?

Close one app: Swipe up from the bottom, hold, then let go. Swipe up on the app. Close all apps: Swipe up from the bottom, hold, then let go.


Video Answer


1 Answers

Closing an app by tapping the back button

Pressing the BACK button, by default, destroys whatever the foreground activity is, returning control to the previous activity (or the home screen if there is no previous activity). It does not "close" an app.

Clearing the app from the recent app list

Usually, this will terminate the app's process. Contrast that with pressing BACK to destroy all of your activities, where the process remains running (at least for a while).

Is there a way to "kill" the app when a user exits with the back button?

Not really. You are better served fixing the bugs in your app.

usually after resuming the app after a long period of time

If "a long period of time" is less than 30 minutes or so, your process may have been terminated while your app was in the background, but Android will try to return the user to wherever the user had been in your app. This involves forking a fresh process for you and recreating your last activity. Sometimes, developers make assumptions that their process always starts with the launcher activity, with bugs being uncovered when the process starts with some other activity.

Also note that the HttpClient implementation in the Android SDK was deprecated in API Level 22 and removed in API Level 23. Either use an independent packaging of HttpClient or use some other HTTP client API (HttpURLConnection, OkHttp, etc.).

like image 87
CommonsWare Avatar answered Oct 13 '22 12:10

CommonsWare