开发者

Android App Exit Button

I'm not sure whether I need to add an exit button to my app.开发者_StackOverflow社区 Is there any point to doing this? And if on exiting one activity or service is not .finish() or closed properly could this cause a lot of damage?


You don't need to add en exit button. If you don't, your activity will just be kept in memory until the system reclaims it. It will not consume any cpu.

Of course, if you have any worker threads running you should stop them in onStop() or onPause(), depending on what your threads are doing.

Many applications add an exit button, for some reason. I guess the reason is that they don't trust themselves to write proper code or they don't trust the Android OS to clean up properly.

Not going through the correct finish procedures will not cause any damage to others than yourself.


Anyone who says you don't need an exit button is right but putting one in never hurts. Users like to see a way to exit to the application, it's not about bad programming, it's actually about proper programming, give the user an exit button and if they never use it great and if it's there even better.


You don't need an exit button in your app. This is how android works. The user is not given any way to actually exit the application.

When you call 'finish', the application stack is just pushed to the background. It still exists in the memory. Android itself decides when to close the application(i.e. remove its instance from the memory) and generally this is done when your application becomes the oldest application which was not used for the longest time.


No, you don't. Read up on the activity lifecycle at developer.android.com

On older versions of android you had to be careful not to accidentally leave a background service running and holding resources but that's been reworked.


Guys you're righteous, but there are some cases when Exit button may have a sense. Let's say you're keeping some application-wide global data in YourApplication class (child of Application), e.g. some sensitive data or so. When user closes final activity and it's destroyed Application won't be terminated. As read Android developer resource - developer should not rely on Application.onTerminate() method. You can easily check it - even in case when all activities closed Application still alive. Whenever Application instance alive it's relatively easy to get access to those object and collect data.

I have found 2 ways how to kill Application class instance:

  1. null'ate all object references (which is hardly possible for large projects) then call garbage collection
  2. call

    android.os.Process.killProcess(android.os.Process.myPid());

So Exit button may have function to finish all activities, call garbage collection then call killProcess() - which will guarantee safe removing of global data stored in Application.


I agree with above post by barmaley.

Long story short, you don't need to exit your application if your concerns are related to the Android system itself. Don't worry, be happy. And that applies especially for lazy users (remember the old Symbian days).

However, if you have something in mind about your application itself, then please go ahead and do it. You can finish the activity, nullify and kill. Just be reasonable because, as always, common sense is going to be better than all the tutorials and references in the world.

Anyway, just my 2c.


From a technical perspective, no, you don't need to add a quit button for all the very good reasons listed here.

Unfortunately users aren't informed in this way and regularly drop review scores because they have to 'use a task killer' or 'force close' your app.

It is a regular request and criticism in reviews/feedback for my app. So it may be necessary to appease users.


I think an exit button can provide the user with assurance that your app is closed.

I know, that it still doesn't mean that the app is definitely closed, but if the user feels more in control with an exit button then I say it is a good idea.


When I first started coding for Android, I thought it was a good idea to manually exit my main activity. What I discovered is that closing the activity via stopSelf leads to corrupt instanceState data, which caused a lot of ANRs when the activity was opened again.

The Activity Lifecycle document is information directly from the Google framework engineers. Every word is for a reason.

Consider that garbage collection takes cpu. This may seem trivial, but in designing a framework for a mobile platform, wouldn't you try to cache as much in memory as possible in case it was needed again, as cpu time = battery, and loading from flash is expensive?

GCing an entire app is non-trivial. Especially when the activity might be used repeatedly. The design had to consider all possible use cases. Cacheing makes sense. The system is designed with this principle.

I would say that not following the Activity Lifecycle document is asking for problems.


Some apps alter the configuration of the device while running or consume lots of CPU or data. You may want to give users an option to Exit the app altogether.

There are proper usecases for an Exit button.

For example, an app i made also needs to manage WiFi networks: the device configuration is changed continuously. Terrific and all while app is in active use, in this case a user would expect the behavior to effectively stop after exiting the application.

So my application has an Exit button mainly to cleanup the WiFi configs it created. I could make a button Stop and Cleanup, but no user would understand. They just want to turn the app off, thus Exit.

  • App running: wifi managed by app.
  • App exited: diy/android wifi.

Right now, choosing Exit in my application does the cleanup followed by a finish(), but the application itself lingers in the background. Functionally ok but confusing users. I could make a toggle action named "wifi feature on/off" but that wont make things simpler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜