微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 活动开始时缺少Intent extras

在广播接收器中,我想启动我的应用程序(Activity)并传入一些数据.

我的问题是额外的东西似乎没有延续到活动中.我试图获取onNewIntent(Intent i)函数内的数据.

有任何想法吗?

这是我目前在broadcastReceiver中的尝试:

Intent intSlider = new Intent();
intSlider.setClass(UAirship.shared().getApplicationContext(),SliderMenuActivity.class);
intSlider.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

intSlider.putExtra("action",ScreensEnum.Object);
intSlider.putExtra("objectId",objectId);
intSlider.putExtra("objectCode",objectCode);
intSlider.putExtra("userId",userId);

UAirship.shared().getApplicationContext().startActivity(intSlider);

编辑 – 添加了onNewIntent()和onCreate()中使用的代码

当应用程序当前未运行时,以下代码在onCreate()中运行良好.当应用程序已经运行时,相同的代码不能从onNewIntent()函数中起作用(即没有额外的).

Intent intent = getIntent();

if(intent.hasExtra("objectId")) {

    loadDetail(intent.getStringExtra("objectId"),"2w232");
}

解决方法

问题是getIntent()方法.它始终返回启动活动的意图,而不是最近的活动.您应该使用传递给onNewIntent方法的intent作为参数.

原文地址:https://www.jb51.cc/android/308602.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐