如果从NFC标签启动,应用程序不会恢复

时间:2013-09-03 13:11:37

标签: android nfc application-restart

我有一个NFC应用程序。如果我不从NFC标签启动它,它甚至可以从通知栏恢复正常,即使长按主页按钮也是如此。问题是当我使用NFC标签启动应用程序时。当我尝试恢复时,它会重新启动应用程序。有什么建议吗?

这是我在清单文件中的启动器活动

<activity
        android:name=".hmi.DebugPreferenceActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:launchMode="singleInstance">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
             <action android:name="android.nfc.action.TECH_DISCOVERED" />
         </intent-filter>

         <meta-data
             android:name="android.nfc.action.TECH_DISCOVERED"
             android:resource="@xml/filter_nfc" />

         <intent-filter>
             <action android:name="android.nfc.action.TAG_DISCOVERED" />

             <category android:name="android.intent.category.DEFAULT" />
         </intent-filter>

    </activity>

这是我创建通知的地方。

private void createNotification() {

Intent notificationIntent = new Intent(mContext, DebugPreferenceActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0,
            notificationIntent, 0);


    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this)
            .setSmallIcon(R.drawable.app_icon)
            .setContentTitle(
                    mContext.getResources().getString(R.string.app_name))
            .setContentIntent(pendingIntent).setContentText(null);
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mBuilder.setOngoing(true);
    mNotificationManager.notify(0, mBuilder.build());

}

0 个答案:

没有答案