Pass data to BroadcastReceiver from Activity using DownloadManager

后端 未结 4 1597
小鲜肉
小鲜肉 2020-12-11 18:35

I am trying to pass an object to a BroadcastReceiver which will do something when a download is finished. How do I access the Intent object in the BroadcastReceiver\'s onRec

4条回答
  •  悲哀的现实
    2020-12-11 19:22

    Before download is executed, save the value in SharedPreference

    editor.putInt(MainActivity.CERIS_LAST_DW_ID_KATALOG, m_intIdKatalog);
    editor.commit();
    

    Then in onReceive get the value from Shared Preference

    @Override
    public void onReceive(Context arg0, Intent arg1) {
        // TODO Auto-generated method stub
        SharedPreferences mCeris;
        mCeris = arg0.getSharedPreferences(MainActivity.CERIS_PREFERENCES,
                Context.MODE_PRIVATE);
    
        int m_intIdKatalog = mCeris.getInt(MainActivity.CERIS_LAST_DW_ID_KATALOG, 0);   
    }
    

提交回复
热议问题