最近使用应用程序时,GetIntent()。getExtras()通常为空-Android

时间:2019-01-10 16:09:31

标签: android android-intent android-manifest

我将应用插入到共享列表中,如下所示:

    <activity
        android:name="xxxx.MainActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|uiMode|orientation|screenSize|smallestScreenSize"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan">
        <meta-data
            android:name="android.app.shortcuts"
            android:resource="@xml/shortcuts" />
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>
    </activity>

然后像下面这样从Intent获取值:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if (getIntent().getExtras() != null) {
        Intent intents = getIntent();
        String action = intents.getAction();
        String type = intents.getType();
        if (action != null && type != null) {
            String receivedUri = intents.getParcelableExtra(Intent.EXTRA_STREAM).toString();
        }
    }
}

问题

但是当我的应用程序最近时,我没有从intent获得任何价值。我该怎么办?

1 个答案:

答案 0 :(得分:2)

最近一次看到您的活动时,GetIntent()。getExtras()将为空。要获取新的Intent,您必须覆盖活动的'getNewIntent'方法

@Override
    protected void onNewIntent(Intent intents)
    {
        super.onNewIntent(intents);

        if (intents != null) {
        String action = intents.getAction();
        String type = intents.getType();
        if (action != null && type != null) {
            String receivedUri = intents.getParcelableExtra(Intent.EXTRA_STREAM).toString();
        }
    }
    }