在工作中,总是遇到一些问题,而今天给大家分享下我遇到的一个问题:
intent传值收不到:
launchMode为singleTask的时候,通过Intent启到一个Activity,如果系统已经存在一个实例,系统就会将请求发送到这个实例上,但这个时候,系统就不会再调用通常情况下我们处理请求数据的onCreate方法,而是调用onNewIntent方法
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);//必须要写
Intent intent = getIntent();
String name = intent.getStringExtra("name");
}
而我们在其他生命周期来获取intent值时null,所以要在onNewIntent方法获取传递回来的intent值在做其他操作;
当Activity的启动模式设置为singleTask时,使用Intent启动该Activity,若已有实例,则系统会将请求发送给现有实例并调用onNewIntent方法而非onCreate方法。本文详细介绍了如何在onNewIntent方法中正确处理Intent数据。

4909

被折叠的 条评论
为什么被折叠?



