android – 来自通知:没有UI的AlertDialog

前端之家收集整理的这篇文章主要介绍了android – 来自通知:没有UI的AlertDialog前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创建一个触发Intent的通知.这是我的代码的一个非常简短的摘录……
Notification notification = new Notification(R.drawable.icon,"notification",System.currentTimeMillis());
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(BackgroundService.this,ConnectionHandler.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);

PendingIntent pendingIntent = PendingIntent.getActivity(context,notificationIntent,0);
notification.setLatestEventInfo(context,getString(R.string.notification_title),getString(R.string.notification_body),pendingIntent);
notification.flags |= notification.FLAG_AUTO_CANCEL;
nm.notify(1,notification);

在我的意图(ConnectionHandler.class)中,我想展示一个有效的AlertDialog.但我希望在不打开新的UI窗口的情况下显示AlertDialog.对我来说最好的是,当点击通知条目时,如果AlertDialog只显示其他任何内容.

任何想法都表示赞赏.

此致,托比

解决方法

Dev Guide

Showing a Dialog

A dialog is always created and displayed as a part of an Activity.

简单的替代方法是创建一个非常基本的Activity,除了对话框之外没有任何内容显示,并在对话框解除后立即调用finish().

原文链接:https://www.f2er.com/android/316564.html

猜你在找的Android相关文章