显示警报Activity.onCreate(..) [英] Displaying alerts in Activity.onCreate(..)

查看:144
本文介绍了显示警报Activity.onCreate(..)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid,这是我在这里的第一个问题,所以请去容易对我。

I am new to Android and this is my first question here so please go easy on me.

是否有可能来检查活动的一些内幕情况的onCreate(),并显示一个AlertDialog?

Is it possible to check some condition inside onCreate() of an Activity and display an AlertDialog?

我创建一个AlertDialog匿名在OnCreate中(),并在该实例上调用秀,但AlertDialog永远不会显示。

I am creating an AlertDialog anonymously in Oncreate() and calling show on that instance but the AlertDialog is never displayed.

推荐答案

显示中的onCreate警告对话框导致android.view.WindowLeaked例外,因为该活动尚未创建。

Showing an alert dialog in onCreate causes android.view.WindowLeaked exception, because the activity isn't yet created.

我找到解决的办法是把code,显示在ONSTART)对话框(方法:

The solution I found is to put the code that shows the dialog in onStart() method:

@Override
protected void onStart() {
    super.onStart();
    // show dialog here
}

这篇关于显示警报Activity.onCreate(..)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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