Save data in Broadcast receiver

前端 未结 5 705
半阙折子戏
半阙折子戏 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:26

    downcast the data to Object class and then up-cast to required class object :-)

    
    public void onReceive(Context context, Intent intent) {
    HashMap map = (HashMap) bundle.get("KEY");
    Object[] data=map.get(mapKey);
    XXXX xxxx=data[0];
    //...
    }
    

提交回复
热议问题