Dealing with SavedInstances, and restoration of activity

前端 未结 2 1292
故里飘歌
故里飘歌 2021-01-27 14:54

basically my app has 2 activities.Say \"A\" and \"B\" . A launches B.

Activity B plays music and also has a notification.

Case 1:when the view is still on activi

相关标签:
2条回答
  • 2021-01-27 15:21

    Basically if you have pressed a back button,restoration of activity should be done using shared preferences/or a database but if you haven't pressed the back button and then you want to restore the state of the activity (because the activity was destroyed by the system ) then the bundle savedinstances can be used ...

    0 讨论(0)
  • 2021-01-27 15:25

    From Android documentation:

    When your activity is destroyed because the user presses Back or the activity finishes itself, the system's concept of that Activity instance is gone forever because the behavior indicates the activity is no longer needed. However, if the system destroys the activity due to system constraints (rather than normal app behavior), then although the actual Activity instance is gone, the system remembers that it existed such that if the user navigates back to it, the system creates a new instance of the activity using a set of saved data that describes the state of the activity when it was destroyed. The saved data that the system uses to restore the previous state is called the "instance state" and is a collection of key-value pairs stored in a Bundle object.

    To fix second problem you must restore data form some other source (service that plays music, restore info from application context or singleton, etc.)

    For more info check this.

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