使用Explicit Intents发送包

时间:2014-10-31 06:51:08

标签: android android-intent

我想从我的图书馆项目发送和意图到我的工作项目(附有该库的那个库)。在这里,我从我的图书馆项目中调用我的活动:

Intent intent = new Intent("isr.LAUNCH");
                intent.setComponent(new ComponentName("com.abc.def", "com.abc.def.screens.BaseActivity_New"));
                intent.putExtra("selectedbook_id",MyReader.BOOK_ID );
                intent.putExtra("isReaderSample", MyReader.IS_SAMPLE);
                intent.putExtra("landing_fragment", "reader_backtrack");
                MyReader.activity.startActivity(intent);
                MyReader.activity.finish();

这就是我在BaseActivity_New中提取bundle的方法:

bundle = getIntent().getExtras();

Activity被正确触发,但是当我在BaseActivity_New的OnResume中检查它时,bundle总是为null,而我的BaseActivity的启动模式是singleInstance

任何人都可以帮我解决如何使用Explicit Intents发送包。

由于

2 个答案:

答案 0 :(得分:1)

因为它是singleInstance我只是看到你编辑答案。

覆盖此方法

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
    //now getIntent() should always return the last received intent
}

答案 1 :(得分:0)

获取数据:

  

String mBookId = getIntent()。getStringExtra(" selectedbook_id");

相关问题