呼叫alertDialog的onStop /的onPause [英] Call alertDialog onStop/onPause

查看:882
本文介绍了呼叫alertDialog的onStop /的onPause的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Override
protected void onStop() {
    super.onStop();

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Test message")
           .setCancelable(true)
           .setPositiveButton("OK", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   dialog.cancel();
               }
           });
    AlertDialog alert = builder.create();
    alert.show();
}

这显然是行不通的,只要所示对话框 - 活动都已停止(对话框消失)。如何解决这个issuse?

This obviously isn't working, as soon as dialog is shown - activity is stopped (dialog disappears). How to solve this issuse?

我想只要活动离开节省一些设置到我的数据库(通过返回按钮,点击按钮的一些导致一些其他活动,点击通知等..),然后显示结果AlertDialog ?

I want to save some setting into my database as soon as activity is left (via back button, clicking on some button which leads to some other activity, click on notification and so on..) and then show the result in AlertDialog?

甚至更好 - 当Android的认识活动将被关闭,这样可以节省我的设置,显示AlertDialog然后的onClick活动终于结束

Or even better - when Android recognizes that activity will be closed, it saves my settings, show AlertDialog and then onClick Activity is finally closed.

推荐答案

这是一个非常不好的做法,尝试做一些事情,需要时间和用户关注的的onStop 的onPause 。通常,这些方法被用来保存一些数据。你可以试着显示吐司,但最好的方法 - 是展示任何东西,因为它不是一个通常的做法。难道真有你需要展示一些东西重要?这是您必须首先解决的问题。

It's a very bad practice to try to do something that takes time and user attention in onStop and onPause. Usually these methods are used to save some data. You can try to show a Toast, but the best way - is to show nothing, as it's not an usual practice. Is there really something important you need to show? This is the question you must resolve in first place.

这篇关于呼叫alertDialog的onStop /的onPause的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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