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

标签 android android-intent

我正在尝试从其他应用程序获取 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/

相关文章:

android - 不要在 Android TextView 中以缩写形式包装文本

java - 未指定资源类型(位于 'id' ,值为 '@+id\st' )

android - 为什么我的 APP 不支持三星 Galaxy Note 3

android - 如何在Android应用程序中创建登录页面?

android - 从其 Activity 启动的服务是否在新线程中运行?

Android - 无法实例化 BroadCastReceiver

Android Studio 构建 transformClassesWithJarMergingForDebug 报错

android - 单击项目时,自定义 ListView 不会在第二个 Activity 中显示图像

android - 如何确保后退按钮在触发 startActivity 后返回到我的应用程序?

Android:确定当前上下文以显示警报