gpt4 book ai didi

android - Intent.getType() 在 onNewIntent(Intent intent ) 方法中返回 null

转载 作者:行者123 更新时间:2023-11-30 01:05:47 26 4
gpt4 key购买 nike

我正在尝试从其他应用程序获取 mime 类型 text/plain 的 Intent 并将该文本存储在字符串类型的变量中。它在 onCreate 方法中工作正常,但是当我使用 singleTask 作为启动模式并暂停应用程序(通过按主页按钮)并尝试将其他应用程序的文本共享到我的应用程序时, onNewIntent(Intent intent) 方法被调用并且 intent.getType() 返回 null,但是 onCreate 方法同样工作正常,我不知道为什么,求助。谢谢

private String sharedData="";
@Override
protected void onNewIntent(Intent intent) {

intent = getIntent();
String action = intent.getAction();

String type = intent.getType(); //this method is returning null

if(intent.ACTION_SEND.equals(action) && type!=null)
{
sharedData = FileHandler.handleSendText(intent);//FileHandler is class i created with contains method handleSendText
}

super.onNewIntent(intent);
}

最佳答案

调用 intent = getIntent(); 将返回提供给 Activity 的原始 intent。因此,它应该为空。尝试删除此行。

关于android - Intent.getType() 在 onNewIntent(Intent intent ) 方法中返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38889876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com