Save data in Broadcast receiver

前端 未结 5 698
半阙折子戏
半阙折子戏 2020-12-11 13:01

I\'d like to maintain a hash table in a broadcast receiver. If I understand BroadcastReceiver\'s life cycle currently it could get killed wiping out my member variables. Wh

5条回答
  •  攒了一身酷
    2020-12-11 13:35

    From the Android Reference:

    A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active.

    Does not sound like what you want to do will work. The Actitivy that registers the receiver will have to take care of this, or you could persist your hash table to the database.

提交回复
热议问题