来自 Android 服务的警报对话框 [英] Alert dialog from Android service

查看:22
本文介绍了来自 Android 服务的警报对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示来自服务的对话框?

How do I display dialog from a service?

推荐答案

android-smspopup 正是这样做的.

一个服务收到一条短信,它开始一个Activity:

A service receives a sms and it starts an Activity with:

android:theme="@android:style/Theme.Dialog"

对话活动开始此处 使用此代码

The dialog activity is started here with this code

private void notifyMessageReceived(SmsMmsMessage message) {
    (...)
    context.startActivity(message.getPopupIntent());
    (...)
}

使用 getPopupIntent() 声明如下(代码 这里):

With getPopupIntent() declared as followed (code here):

public Intent getPopupIntent() {
    Intent popup = new Intent(context, SmsPopupActivity.class);
    popup.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    popup.putExtras(toBundle());
    return popup;
    }

SmsPopupActivity 类显然定义了对话框活动.其声明如下 AndroidManifest.xml:

    <activity
        android:name=".ui.SmsPopupActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:launchMode="singleTask"
        android:screenOrientation="user"
        android:taskAffinity="net.everythingandroid.smspopup.popup"
        android:theme="@style/DialogTheme" >
    </activity>

这篇关于来自 Android 服务的警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆