Android:ProgressDialog.show() 与 getApplicationContext 崩溃

发布于 2024-08-07 10:17:20 字数 3081 浏览 8 评论 0原文

我似乎无法理解为什么会发生这种情况。这段代码:

mProgressDialog = ProgressDialog.show(this, "", getString(R.string.loading), true);

工作得很好。但是,此代码:

mProgressDialog = ProgressDialog.show(getApplicationContext(), "", getString(R.string.loading), true);

引发以下异常:

W/WindowManager(  569): Attempted to add window with non-application token WindowToken{438bee58 token=null}.  Aborting.
D/AndroidRuntime( 2049): Shutting down VM
W/dalvikvm( 2049): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
E/AndroidRuntime( 2049): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 2049): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tastekid.TasteKid/com.tastekid.TasteKid.YouTube}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
E/AndroidRuntime( 2049):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
E/AndroidRuntime( 2049):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 2049):    at android.app.ActivityThread.access$2100(ActivityThread.java:116)
E/AndroidRuntime( 2049):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
E/AndroidRuntime( 2049):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2049):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2049):    at android.app.ActivityThread.main(ActivityThread.java:4203)
E/AndroidRuntime( 2049):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2049):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2049):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime( 2049):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
E/AndroidRuntime( 2049):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2049): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
E/AndroidRuntime( 2049):    at android.view.ViewRoot.setView(ViewRoot.java:460)
E/AndroidRuntime( 2049):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
E/AndroidRuntime( 2049):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/AndroidRuntime( 2049):    at android.app.Dialog.show(Dialog.java:238)
E/AndroidRuntime( 2049):    at android.app.ProgressDialog.show(ProgressDialog.java:107)
E/AndroidRuntime( 2049):    at android.app.ProgressDialog.show(ProgressDialog.java:90)
E/AndroidRuntime( 2049):    at com.tastekid.TasteKid.YouTube.onCreate(YouTube.java:45)
E/AndroidRuntime( 2049):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
E/AndroidRuntime( 2049):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
E/AndroidRuntime( 2049):    ... 11 more

有什么想法为什么会发生这种情况吗?我从 onCreate 方法调用它。

I can't seem to grasp why this is happening. This code:

mProgressDialog = ProgressDialog.show(this, "", getString(R.string.loading), true);

works just fine. However, this code:

mProgressDialog = ProgressDialog.show(getApplicationContext(), "", getString(R.string.loading), true);

throws the following exception:

W/WindowManager(  569): Attempted to add window with non-application token WindowToken{438bee58 token=null}.  Aborting.
D/AndroidRuntime( 2049): Shutting down VM
W/dalvikvm( 2049): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
E/AndroidRuntime( 2049): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 2049): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tastekid.TasteKid/com.tastekid.TasteKid.YouTube}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
E/AndroidRuntime( 2049):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
E/AndroidRuntime( 2049):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 2049):    at android.app.ActivityThread.access$2100(ActivityThread.java:116)
E/AndroidRuntime( 2049):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
E/AndroidRuntime( 2049):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2049):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2049):    at android.app.ActivityThread.main(ActivityThread.java:4203)
E/AndroidRuntime( 2049):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2049):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2049):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime( 2049):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
E/AndroidRuntime( 2049):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2049): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
E/AndroidRuntime( 2049):    at android.view.ViewRoot.setView(ViewRoot.java:460)
E/AndroidRuntime( 2049):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
E/AndroidRuntime( 2049):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/AndroidRuntime( 2049):    at android.app.Dialog.show(Dialog.java:238)
E/AndroidRuntime( 2049):    at android.app.ProgressDialog.show(ProgressDialog.java:107)
E/AndroidRuntime( 2049):    at android.app.ProgressDialog.show(ProgressDialog.java:90)
E/AndroidRuntime( 2049):    at com.tastekid.TasteKid.YouTube.onCreate(YouTube.java:45)
E/AndroidRuntime( 2049):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
E/AndroidRuntime( 2049):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
E/AndroidRuntime( 2049):    ... 11 more

Any ideas why this is happening? I'm calling this from the onCreate method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

素食主义者 2024-08-14 10:17:21

尝试 -

AlertDialog.Builder builder = new AlertDialog.Builder(getParent());

Try -

AlertDialog.Builder builder = new AlertDialog.Builder(getParent());
慢慢从新开始 2024-08-14 10:17:21

(兼容性)片段也有类似的问题,其中在 ProgressDialog.show() 中使用 getActivity() 会导致崩溃。我同意这是因为时机。

一个可能的解决方案:

mContext = getApplicationContext();

if (mContext != null) {
    mProgressDialog = ProgressDialog.show(mContext, "", getString(R.string.loading), true);
}

而不是使用

mProgressDialog = ProgressDialog.show(getApplicationContext(), "", getString(R.string.loading), true);

尽早放置 mContext,以便有更多时间来获取上下文。仍然不能保证这会起作用,它只是降低了崩溃的可能性。如果它仍然不起作用,您就必须求助于计时器黑客(这可能会导致其他计时问题,例如稍后关闭对话框)。

当然,如果您可以使用 thisActivityName.this,它会更稳定,因为 this 已经指向某些内容。但在某些情况下,比如某些 Fragment 架构,这不是一个选择。

Had a similar problem with (compatibility) Fragments in which using a getActivity() within ProgressDialog.show() crashes it. I'd agree that it is because of timing.

A possible fix:

mContext = getApplicationContext();

if (mContext != null) {
    mProgressDialog = ProgressDialog.show(mContext, "", getString(R.string.loading), true);
}

instead of using

mProgressDialog = ProgressDialog.show(getApplicationContext(), "", getString(R.string.loading), true);

Place the mContext as early as possible to give it more time to grab the context. There's still no guarantee that this will work, it just reduces the likelihood of a crash. If it still doesn't work, you'd have to resort to the timer hack (which can cause other timing problems like dismissing the dialog later).

Of course, if you can use this or ActivityName.this, it's more stable because this already points to something. But in some cases, like with certain Fragment architectures, it's not an option.

抽个烟儿 2024-08-14 10:17:21

(供将来参考)

我认为这是因为应用程序上下文和活动上下文存在差异,如下所述: http://www.doubleencore.com/2013/06/context/

这意味着我们无法使用应用程序上下文显示对话框。就是这样。

(For future references)

I think it's because there's differences in Application Context and Activity Context, as explained here: http://www.doubleencore.com/2013/06/context/

Which means that we can't show dialog using Application Context. That's it.

此生挚爱伱 2024-08-14 10:17:21

要在 Activity 内使用对话框,请按以下方式操作:

private Context mContext;
private AlertDialog.Builder mBuilder;

@Override
protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     mContext = this;

     //using mContext here refering to activity context
     mBuilder = new AlertDialog.Builder(mContext);
     //...
     //rest of the code
     //...
}

若要在 Fragment 内使用对话框,请按以下方式操作:

private Context mContext;
private AlertDialog.Builder mBuilder;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View mRootView = inflater.inflate(R.layout.fragment_layout, container, false);
      mContext = getActivity();

      //using mContext here refering to fragment's hosting activity context
      mBuilder = new AlertDialog.Builder(mContext);
      //...
      //rest of the code
      //...
      return mRootView;
}

就是这样 ^_^

For using dialogs inside activities, do it this way:

private Context mContext;
private AlertDialog.Builder mBuilder;

@Override
protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     mContext = this;

     //using mContext here refering to activity context
     mBuilder = new AlertDialog.Builder(mContext);
     //...
     //rest of the code
     //...
}

For using dialogs inside fragments, do it this way:

private Context mContext;
private AlertDialog.Builder mBuilder;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View mRootView = inflater.inflate(R.layout.fragment_layout, container, false);
      mContext = getActivity();

      //using mContext here refering to fragment's hosting activity context
      mBuilder = new AlertDialog.Builder(mContext);
      //...
      //rest of the code
      //...
      return mRootView;
}

That's it ^_^

混吃等死 2024-08-14 10:17:21

为了解决这个问题,我所做的就是为我存储全局数据的所有活动创建一个基类。在第一个活动中,我将上下文保存在基类的变量中,如下所示:

基类

public static Context myucontext; 

第一个活动从基类派生

mycontext = this

然后在创建对话框时使用 mycontext 而不是 getApplicationContext。

AlertDialog alertDialog = new AlertDialog.Builder(mycontext).create();

What I did to get around this was to create a base class for all my activities where I store global data. In the first activity, I saved the context in a variable in my base class like so:

Base Class

public static Context myucontext; 

First Activity derived from the Base Class

mycontext = this

Then I use mycontext instead of getApplicationContext when creating dialogs.

AlertDialog alertDialog = new AlertDialog.Builder(mycontext).create();
小清晰的声音 2024-08-14 10:17:21

如果您在片段中调用 ProgressDialog.show() ,则将 mContext 转换为 Activity 对我有用。

     ProgressDialog pd = new ProgressDialog((Activity) mContext);

If you're calling ProgressDialog.show() in a fragment, casting the mContext to Activity worked for me.

     ProgressDialog pd = new ProgressDialog((Activity) mContext);
鲜血染红嫁衣 2024-08-14 10:17:21

这是一个常见问题。
使用 this 而不是 getApplicationContext()
这应该可以解决你的问题

This is a common problem.
Use this instead of getApplicationContext()
That should solve your problem

源来凯始玺欢你 2024-08-14 10:17:21

我已经实现了警报对话框,用于将异常抛出到当前活动视图。每当我给出这样的

AlertDialog.Builder builder = new AlertDialog.Builder(context);

给定相同的窗口异常时。我在 onCreate() 之外编写警报代码。如此简单,我使用了 context = this;context = this; 在 onCreate() 方法中的 setContentView() 语句之后。将上下文变量视为全局变量,如 Context context;

代码示例是

static Context context;

 public void onCreate(Bundle savedInstanceState)  { 
        super.onCreate(savedInstanceState); 


        setContentView(R.layout.network); 
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        context = this;
.......

Alert 方法示例是

private void alertException(String execMsg){
        Log.i(TAG,"in alertException()..."+context);
        Log.e(TAG,"Exception :"+execMsg);
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
.......

它对我来说效果很好。实际上,我在 StackOverflow 上搜索了这个错误,我发现了这个查询。在阅读了这篇文章的所有回复后,我尝试了这种方式,所以它有效。我认为这是克服异常的简单解决方案。

谢谢,
拉詹达尔

I have implemented Alert Dialog for exception throwing on to the current activitty view.Whenever I had given like this

AlertDialog.Builder builder = new AlertDialog.Builder(context);

Given same Window Exception.I write code for alert out of onCreate().So simple I used context = this; after setContentView() statement in onCreate() method.Taken context variable as global like Context context;

Code sample is

static Context context;

 public void onCreate(Bundle savedInstanceState)  { 
        super.onCreate(savedInstanceState); 


        setContentView(R.layout.network); 
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        context = this;
.......

Alert Method Sample is

private void alertException(String execMsg){
        Log.i(TAG,"in alertException()..."+context);
        Log.e(TAG,"Exception :"+execMsg);
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
.......

It works fine for me.Actually I searched for this error on StackOverflow I found this query.After reading all responses of this post, I tried this way so It works .I thought this is a simple solution for overcome the exception.

Thanks,
Rajendar

美人骨 2024-08-14 10:17:21

如果您在 groupActivity 上遇到问题,请不要使用它。
PARENT 是来自 Parent ActivityGroup 的静态值。

final AlertDialog.Builder builder = new AlertDialog.Builder(GroupActivityParent.PARENT);

而不是

final AlertDialog.Builder builder = new AlertDialog.Builder(getParent());

if you have a problem on groupActivity dont use this.
PARENT is a static from the Parent ActivityGroup.

final AlertDialog.Builder builder = new AlertDialog.Builder(GroupActivityParent.PARENT);

instead of

final AlertDialog.Builder builder = new AlertDialog.Builder(getParent());
っ左 2024-08-14 10:17:21

对话框始终作为活动的一部分创建和显示。您需要传入 Activity 上下文而不是应用程序上下文。

http://developer.android.com/guide/topics/ui/dialogs .html#ShowingADialog

A dialog is always created and displayed as a part of an Activity. You need to pass in an Activity context instead of the Application context.

http://developer.android.com/guide/topics/ui/dialogs.html#ShowingADialog

云胡 2024-08-14 10:17:20

我使用的是 Android 版本 2.1 和 API 级别 7。我遇到了这个(或类似的)问题,并通过使用以下方法解决:

Dialog dialog = new Dialog(this);

而不是这个:

Dialog dialog = new Dialog(getApplicationContext());

I am using Android version 2.1 with API Level 7. I faced with this (or similar) problem and solved by using this:

Dialog dialog = new Dialog(this);

instead of this:

Dialog dialog = new Dialog(getApplicationContext());
浅暮の光 2024-08-14 10:17:20

对我来说,改变工作

builder = new AlertDialog.Builder(getApplicationContext());

builder = new AlertDialog.Builder(ThisActivityClassName.this);

奇怪,第一个可以在谷歌教程中找到,人们在这方面遇到错误。

For me worked changing

builder = new AlertDialog.Builder(getApplicationContext());

to

builder = new AlertDialog.Builder(ThisActivityClassName.this);

Weird thing is that the first one can be found in google tutorial and people get error on this..

千纸鹤带着心事 2024-08-14 10:17:20

您使用的是哪个 API 版本?如果我对问题所在的理解是正确的,那么这个问题已在 Android 1.6(API 版本 4)中得到修复。

看起来 getApplicationContext() 返回的对象引用只是指向 null。我认为您遇到的问题与我遇到的问题类似,即 onCreate() 中的一些代码在窗口实际构建完成之前运行。这将是一个黑客,但尝试在几百毫秒内启动一个新线程(IIRC:300-400似乎对我有用,但你需要修补),打开你的 ProgressDialog 并启动你需要的任何其他内容(例如网络IO)。像这样的东西:

@Override
public void onCreate(Bundle savedInstanceState) {
    // do all your other stuff here

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            mProgressDialog = ProgressDialog.show(
               YouTube.this.getApplicationContext(), "",
               YouTube.this.getString(R.string.loading), true);

            // start time consuming background process here
        }
    }, 1000); // starting it in 1 second
}

Which API version are you using? If I'm right about what the problem is then this was fixed in Android 1.6 (API version 4).

It looks like the object reference that getApplicationContext() is returning just points to null. I think you're having a problem similar to one I had in that some of the code in the onCreate() is being run before the window is actually done being built. This is going to be a hack, but try launching a new Thread in a few hundred milliseconds (IIRC: 300-400 seemed to work for me, but you'll need to tinker) that opens your ProgressDialog and starts anything else you needed (eg. network IO). Something like this:

@Override
public void onCreate(Bundle savedInstanceState) {
    // do all your other stuff here

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            mProgressDialog = ProgressDialog.show(
               YouTube.this.getApplicationContext(), "",
               YouTube.this.getString(R.string.loading), true);

            // start time consuming background process here
        }
    }, 1000); // starting it in 1 second
}
夜清冷一曲。 2024-08-14 10:17:20

我不认为这是围绕空应用程序上下文的计时问题

尝试在您的应用程序中扩展应用程序(或者如果您已经有,则直接使用它)

public class MyApp extends Application

使实例可用作私有单例。这是never null

private static MyApp appInstance;

在MyApp中创建一个静态助手(它将使用单例)

    public static void showProgressDialog( CharSequence title, CharSequence message )
{
    prog = ProgressDialog.show(appInstance, title, message, true); // Never Do This!
}

BOOM!!

此外,请在此处查看android工程师的答案:WindowManager$BadTokenException

导致此错误的原因之一可能是尝试显示应用程序
通过不是 Activity 的 Context 进行窗口/对话框。

现在,我同意,该方法采用 Context 参数而不是 Activity 是没有意义的。

I don't think this is a timing issue around a null application context

Try extending Application within your app (or just use it if you already have)

public class MyApp extends Application

Make the instance available as a private singleton. This is never null

private static MyApp appInstance;

Make a static helper in MyApp (which will use the singleton)

    public static void showProgressDialog( CharSequence title, CharSequence message )
{
    prog = ProgressDialog.show(appInstance, title, message, true); // Never Do This!
}

BOOM!!

Also, check out android engineer's answer here: WindowManager$BadTokenException

One cause of this error may be trying to display an application
window/dialog through a Context that is not an Activity.

Now, i agree, it does not make sense that the method takes a Context param, instead of Activity..

奢欲 2024-08-14 10:17:20

阅读上述答案后,我发现对于我的情况,以下解决了问题。

这引发了错误

myButton.setOnClickListener(new OnClickListener(){
    public void onClick(View v) {
        MyDialogue dialog = new MyDialogue(getApplicationContext());
        dialog.show();              
    }
});

基于之前的答案表明上下文是错误的,我更改了 getApplicationContext() 以从传递到按钮 onClick 方法的视图中检索上下文。

myButton.setOnClickListener(new OnClickListener(){
    public void onClick(View v) {
        MyDialogue dialog = new MyDialogue(v.getContext());
        dialog.show();              
    }
});

我不完全理解Java的工作原理,所以我可能是错的,但我猜测对于我的具体情况,原因可能与上面的代码片段是在抽象活动类中定义的事实有关;被许多 Activity 继承和使用,也许这导致了 getApplicationContext() 不返回有效上下文的事实? (只是猜测)。

Having read the above answers i found that for my situation the following fixed the issue.

This threw the error

myButton.setOnClickListener(new OnClickListener(){
    public void onClick(View v) {
        MyDialogue dialog = new MyDialogue(getApplicationContext());
        dialog.show();              
    }
});

Based on the previous answers that suggested the context was the wrong one, i changed the getApplicationContext() to retrieve the context from the View passed in to the buttons onClick method.

myButton.setOnClickListener(new OnClickListener(){
    public void onClick(View v) {
        MyDialogue dialog = new MyDialogue(v.getContext());
        dialog.show();              
    }
});

I don't fully understand the workings of Java so i could be wrong, but I'm guessing that for my specific situation the cause could have been related to the fact that the above snippet was defined in an Abstract Activity class; inherited and used by many Activities, perhaps that contributed to the fact that getApplicationContext() doesn't return a valid context?? (Just a guess).

从﹋此江山别 2024-08-14 10:17:20

我正在创建一个带有逐项叠加的地图视图。我正在从我的mapActivity创建我的itemizedoverlay:

OCItemizedOverlay currentLocationOverlay = new OCItemizedOverlay(pin,getApplicationContext);

我发现当我的itemizedoverlay的onTap方法被触发时,我会得到“android.view.WindowManager$BadTokenException:无法添加窗口——令牌null不适用于应用程序”异常(当在地图视图上点击该位置时)。

我发现如果我只是将“this”而不是“getApplicationContext()”传递给我的构造函数,问题就消失了。这似乎支持了alienjazzcat的结论。诡异的。

I am creating a map view with itemized overlays. I was creating my itemizedoverlay like this from my mapActivity:

OCItemizedOverlay currentLocationOverlay = new OCItemizedOverlay(pin,getApplicationContext);

I found that I would get the "android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application" exception when my itemizedoverlay's onTap method was triggered(when the location is tapped on the mapview).

I found that if I simply passed, 'this' instead of 'getApplicationContext()' to my constructor, the problem went away. This seems to support alienjazzcat's conclusion. weird.

是你 2024-08-14 10:17:20

对于 TabActivities 中显示的活动,请使用 getParent()

final AlertDialog.Builder builder = new AlertDialog.Builder(getParent());

而不是

final AlertDialog.Builder builder = new AlertDialog.Builder(this);

For Activities shown within TabActivities use getParent()

final AlertDialog.Builder builder = new AlertDialog.Builder(getParent());

instead of

final AlertDialog.Builder builder = new AlertDialog.Builder(this);
笑饮青盏花 2024-08-14 10:17:20

适用于 Android 2.2
使用此代码:

//activity is an instance of a class which extends android.app.Activity
Dialog dialog = new Dialog(activity);

而不是此代码:

// this code produces an ERROR:
//android.view.WindowManager$BadTokenException: 
//Unable to add window -- token null is not for an application
Context mContext = activity.getApplicationContext();
Dialog dialog = new Dialog(mContext);

备注:我的自定义对话框是在 activity.onCreateDialog(int dialId) 方法之外创建的。

For Android 2.2
Use this code:

//activity is an instance of a class which extends android.app.Activity
Dialog dialog = new Dialog(activity);

instead of this code:

// this code produces an ERROR:
//android.view.WindowManager$BadTokenException: 
//Unable to add window -- token null is not for an application
Context mContext = activity.getApplicationContext();
Dialog dialog = new Dialog(mContext);

Remark: My custom dialog is created outside activity.onCreateDialog(int dialogId) method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文