17

通知からアプリを起動すると、アプリの 1 つで問題が発生します。「最近のアプリ」リストには表示されません。

通知がなければ、すべてが期待どおりに機能します。アプリを起動してナビゲートし、終了すると(ホームボタンまたは戻るボタンで)、ホームボタンを長押しして戻ることができます=> OK。

問題は、通知を受け取ったときに始まります。通知からアプリを起動すると、正しい画面が起動し、アプリを使用できます => OK。しかし、アプリを(ホームまたは戻るボタンで)終了すると、「最近のアプリ」リストに表示されなくなります。より正確に:

  • 通知からアプリを起動する前にアプリが「最近のアプリ」リストに存在していた場合は、それを削除します
  • アプリが「最近のアプリ」リストに存在しない場合、追加されません

以下、ステータスバーに通知を追加する元のコード:

mNotification = new Notification(R.drawable.ic_notif, message, System.currentTimeMillis());
mNotification.flags |= Notification.FLAG_AUTO_CANCEL;

Intent notificationIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(link));
notificationIntent.putExtra(...);

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
mNotification.setLatestEventInfo(context, context.getString(R.string.app_name), message, contentIntent);
notificationManager.notify(ConfigApp.NOTIFICATION_ID, mNotification);

FLAG_ACTIVITY_NEW_TASKを追加しようとしましたが、役に立ちませんでした:

Intent notificationIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(link));
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.putExtra(...);

通知によって開始されたアクティビティのマニフェスト宣言:

<activity
    android:name=".activity.ActivityMessages"
    android:label=""
    android:windowSoftInputMode="stateHidden">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:host="hostapp"
            android:pathPrefix="/prefixapp"
            android:scheme="schemeapp" />
    </intent-filter>
</activity>

通知から開始された後、アプリを「最近のアプリ」リストに保持する方法を知っている人はいますか?

4

5 に答える 5

8

android.intent.action.MAINアクションとカテゴリandroid.intent.category.LAUNCHERをアクティビティの仕様に追加します。2 つのアクションとカテゴリを持つことはハックのように見えますが、実際には Android でサポートされています

<activity
    android:name=".activity.ActivityMessages"
    android:label=""
    android:windowSoftInputMode="stateHidden">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <data
            android:host="hostapp"
            android:pathPrefix="/prefixapp"
            android:scheme="schemeapp" />
    </intent-filter>
</activity>

これにより、最近のアプリケーション リストに追加されます。理由は、Android 開発者向けドキュメントに記載されています。

この種のインテント フィルターにより、アクティビティのアイコンとラベルがアプリケーション ランチャーに表示され、ユーザーはアクティビティを起動し、起動後にいつでも作成されたタスクに戻ることができます。

この 2 番目の機能は重要です。ユーザーはタスクを終了し、後でこのアクティビティ ランチャーを使用してタスクに戻ることができる必要があります。このため、アクティビティが常にタスクを開始するようにマークする 2 つの起動モード「singleTask」と「singleInstance」は、アクティビティに ACTION_MAIN フィルタと CATEGORY_LAUNCHER フィルタがある場合にのみ使用する必要があります 。 The filter is missing: Intent launches a "singleTask" activity, initiating a new task, and the user uses some time working in that task. The user presses the Home button. タスクはバックグラウンドに送信され、表示されなくなります。アプリケーションランチャーにタスクが表示されないため、ユーザーはタスクに戻ることができません。

于 2012-09-15T19:05:34.850 に答える
0

マニフェストに次を追加してみてください。

android:excludeFromRecents = "false"

がんばれ、ルイス

于 2012-09-18T15:45:22.120 に答える
0

Intent Filtersアクション/カテゴリのペアごとに個別に使用する必要があります。

<activity
    android:name=".activity.ActivityMessages"
    android:label=""
    android:windowSoftInputMode="stateHidden">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:host="hostapp"
            android:pathPrefix="/prefixapp"
            android:scheme="schemeapp" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <data
            android:host="hostapp"
            android:pathPrefix="/prefixapp"
            android:scheme="schemeapp" />
    </intent-filter>
</activity>
于 2012-09-18T20:38:50.803 に答える