我试图从其他应用程序获得mime类型text/plain的意图,并将该文本存储在类型字符串的变量中。它从onCreate方法工作良好,但当我使用singleTask作为启动模式并暂停应用程序(通过按home键)并尝试从其他应用程序共享文本到我的应用程序,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();
将返回提供给活动的原始intent
。因此,它应该为空。