Android App Exit Button

后端 未结 10 1266
鱼传尺愫
鱼传尺愫 2020-12-18 02:07

I\'m not sure whether I need to add an exit button to my app. Is there any point to doing this? And if on exiting one activity or service is not .finish() or closed properly

相关标签:
10条回答
  • 2020-12-18 02:15

    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.

    0 讨论(0)
  • 2020-12-18 02:15

    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.

    0 讨论(0)
  • 2020-12-18 02:16

    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.

    0 讨论(0)
  • 2020-12-18 02:18

    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 讨论(0)
  • 2020-12-18 02:26

    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.

    0 讨论(0)
  • 2020-12-18 02:30

    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.

    0 讨论(0)
提交回复
热议问题