GetIntent (). GetExtras () часто пусто, когда приложение недавно - Android - PullRequest
0 голосов
/ 10 января 2019

Я вставил свое приложение в список, как показано ниже:

    <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 голосов
/ 10 января 2019

Когда ваша активность станет видимой из недавних, 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();
        }
    }
    }
...