Android 尝试为Pren手机创建Whatsapps快速回复
我正在尝试创建一个小窗口,如果您单击通知上的“快速回复”按钮,该窗口将打开。在WhatsApp中,它打开了一个半屏幕窗口。目前我正在做以下工作: 我打开了一个名为Android 尝试为Pren手机创建Whatsapps快速回复,android,notifications,Android,Notifications,我正在尝试创建一个小窗口,如果您单击通知上的“快速回复”按钮,该窗口将打开。在WhatsApp中,它打开了一个半屏幕窗口。目前我正在做以下工作: 我打开了一个名为NotificationActivity的活动。在AndroidManifest.xml中,我将活动注册为 <activity android:name=".activity.NotificationActivity" android:theme="@style/Theme.AppCompat.Light.Dial
NotificationActivity
的活动。在AndroidManifest.xml
中,我将活动注册为
<activity
android:name=".activity.NotificationActivity"
android:theme="@style/Theme.AppCompat.Light.Dialog.custom"
android:label="@string/title_activity_notification"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden" />
要实现所需的功能,需要使用值为
singleInstance
的属性:
与“singleTask”
相同,只是系统不启动任何其他任务
将活动添加到包含实例的任务中。活动总是很有趣
任务中唯一的一个成员
您还应该添加android:excludeFromRecents=“true”
,将您的活动从最近使用的应用程序列表中排除,如下所述:
是否应排除此活动启动的任务
从最近使用的应用程序列表中,显示概览屏幕。那个
是指,当此活动是新任务的根活动时
属性确定任务是否不应出现在任务列表中
最近的应用程序。如果任务应该从列表中排除,则设置“true”;
如果应该包含,则将其设置为“false”。默认值为“false”
总结一下,您需要如下更改您的AndroidManifest.xml
:
<activity
android:name=".activity.NotificationActivity"
android:theme="@style/Theme.AppCompat.Light.Dialog.custom"
android:label="@string/title_activity_notification"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden"
android:launchMode="singleInstance"
android:excludeFromRecents="true" />
根据所述通知启动特殊活动 对于这种情况,请将
pendingent
设置为以新的方式启动
任务但是,不需要创建后堆栈,因为
启动的活动不是应用程序活动流的一部分。
单击“上一步”仍然会将用户带到主屏幕
特殊活动不需要后台堆栈,因此不必在清单中定义其活动层次结构,也不必调用addParentStack()
来构建后台堆栈。相反,使用清单设置活动任务选项,并通过调用getActivity()
,创建pendingent
:
android:name="activityclass"
活动的完全限定类名
与您在代码中设置的FLAG\u ACTIVITY\u NEW\u TASK
标志相结合,可以确保此活动不会进入应用程序的
默认任务。具有应用程序默认设置的任何现有任务
亲和力不受影响
从最近的任务中排除新任务,以便用户不会意外地导航回该任务
<activity
android:name=".YourActivity"
android:theme="@style/Theme.AppCompat.Light.Dialog.custom"
...
android:launchMode="singleTask"
android:taskAffinity=""
android:excludeFromRecents="true">
</activity>
如果需要,也请检查该官员
希望这对你有帮助
<activity
android:name=".activity.NotificationActivity"
android:theme="@style/Theme.AppCompat.Light.Dialog.custom"
android:label="@string/title_activity_notification"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden"
android:launchMode="singleInstance"
android:excludeFromRecents="true" />
android:name="activityclass"
android:taskAffinity=""
android:excludeFromRecents="true"
<activity
android:name=".YourActivity"
android:theme="@style/Theme.AppCompat.Light.Dialog.custom"
...
android:launchMode="singleTask"
android:taskAffinity=""
android:excludeFromRecents="true">
</activity>
// Instantiate a Builder object.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
// Creates an Intent for the Activity
Intent notifyIntent =
new Intent(this, ResultActivity.class);
// Sets the Activity to start in a new, empty task
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
// Creates the PendingIntent
PendingIntent notifyPendingIntent =
PendingIntent.getActivity(
this,
0,
notifyIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
// Puts the PendingIntent into the notification builder
builder.setContentIntent(notifyPendingIntent);
// Notifications are issued by sending them to the
// NotificationManager system service.
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Builds an anonymous Notification object from the builder, and
// passes it to the NotificationManager
mNotificationManager.notify(id, builder.build());