【问题标题】:display dialog of another activity in android在android中显示另一个活动的对话框
【发布时间】:2012-07-20 10:40:13
【问题描述】:
【问题讨论】:
标签:
android
android-activity
dialog
【解决方案1】:
首先在 Activity 2 中创建单独的对话框,然后执行下面提到的操作
- 在收到与活动 1 相关的数据时尝试发送广播。
- 创建一个接收广播的接收器类
- 现在您必须使用观察者设计模式,即当 Receiver 类中发生某些事件时,它将通知 Activity B 数据已到达并显示相应的对话框。
如果不成功,请分享结果。
【解决方案2】:
在你的第一个活动(splashScreen)中编写这个函数来创建警报框
public static void MyAlertBox(String title, String mymessage, Context context)
{
new AlertDialog.Builder(context)
.setMessage(mymessage)
.setTitle(title)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
.
}
})
.show();
}
声明全局可验证:
public static Activity currentActivity= null;
在每个活动中:
onResume() 写“currentActivity=this;”
你想在哪里显示警报只需写:(活动 1)
SplashScreen.MyAlertBox("Alert",
"Alert box from activity 1",currentActivity );
希望对你有用!!