【问题标题】:Android singleTop Activity issueAndroid singleTop Activity 问题
【发布时间】:2018-03-24 10:03:15
【问题描述】:

我在清单文件中将我的活动声明为 singleTop。 我在启动此活动时有意传递一些价值。

Intent i= new Intent(A.this,MysingleTopActivity.class);
i.putExtra("isActive",true);
startActivity(i);

我正在为 B 类的重新启动活动执行相同的步骤。

Intent i= new Intent(B.this,MysingleTopActivity.class);
i.putExtra("isActive",false);
startActivity(i);

为此,我接到了 MysingleTopActivity 的 onNewIntent() 方法的调用。 isActive =false

但如果我旋转屏幕,onCreate() 将调用并在那个“isActive=true”中。

如何检索该活动的当前实例值?

谢谢

【问题讨论】:

  • 你在 onNewIntent 中设置了 Intent 吗?
  • @Parth 你需要在 onNewIntent() 方法中设置意图,以便下次更新意图
  • 不,我没有在 onNewIntent() 方法中设置意图。我尝试了它起作用的既定意图。非常感谢。
  • 请回答您自己的问题并接受答案。这将对其他人有所帮助,并将其从未回答的问题列表中删除。

标签: android android-activity launchmode


【解决方案1】:

为了实现这个结果需要添加

setIntent(newintent); 

onNewIntent(Intent newintent) {}methold 中,屏幕newintent 的旋转将在onCreate() 上传递;

示例代码:

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
//add your code
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    相关资源
    最近更新 更多