Wear app打开从磨损通知打开的多个活动

时间:2016-07-02 07:42:26

标签: android android-activity wear-os

我已经通过pIntent为我的磨损应用创建了一个通知。因此,当我单击通知上的打开按钮时,应用程序将打开一个新活动,而不是已经运行的活动。我在清单中有singleTask。我也尝试在手机上这样做,然后它完美无缺。

这是我的穿着清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bowandarrow.sondre.intervaltimer">

    <uses-feature android:name="android.hardware.type.watch" />

    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:supportsRtl="true"
        android:theme="@android:style/Theme.DeviceDefault">
        <uses-library
            android:name="com.google.android.wearable"
            android:required="false" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".timer"
            android:label="@string/title_activity_timer"
            android:launchMode="singleTask"
            ></activity>
    </application>

</manifest>

这是我的磨损java文件代码:

intent = new Intent(timer.this, timer.class);
                pIntent = PendingIntent.getActivity(timer.this, 0, intent, 0);

                notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
                notification = new Notification.Builder(timer.this)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentIntent(pIntent)
                        .setContentTitle("Interval Training Timer")
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setContentText("WORK" +  " - " + "Time remaining: " + minutescountdown + ":" + secondscountdown)
                        .build();
                notificationManager.notify(0,notification);

这是我的手机清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bowandarrow.sondre.intervaltimer">

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".add" />
        <activity
            android:name=".timer"
            android:label="@string/title_activity_timer"
            android:launchMode="singleTask"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name=".settings" />
        <activity android:name=".congratulation" />
    </application>

</manifest>

这是我的手机java文件代码:

Intent intent = new Intent(timer.this, timer.class);
                PendingIntent pIntetn = PendingIntent.getActivity(timer.this, 0, intent, 0);

            notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
            notification = new Notification.Builder(timer.this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentIntent(pIntetn)
                    .setContentTitle(clickedinterval)
                    .setContentText(getString(R.string.Pause_little) + " - " + getString(R.string.time_reamining_notifi) + " " + minutesPauseCountDown + ":" + secondsPauseCountDown)
                    .setPriority(Notification.PRIORITY_HIGH)
                    .build();

            notification.flags = Notification.FLAG_AUTO_CANCEL;
            notificationManager.notify(0, notification);

0 个答案:

没有答案