Android App Exit Button

后端 未结 10 1276
鱼传尺愫
鱼传尺愫 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

    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.

提交回复
热议问题