开发者

What's up with different contexts in android? [duplicate]

开发者 https://www.devze.com 2023-03-12 16:16 出处:网络
This question already has an answer here: Diffinitive rules for using Android's getBaseContext, getApplicationContext or using an Activity's "this"
This question already has an answer here: Diffinitive rules for using Android's getBaseContext, getApplicationContext or using an Activity's "this" 开发者_StackOverflow中文版 (1 answer) Closed 8 years ago.

What's the difference between myClass.this and getBaseContext? When I put an AlertDialog in a different class and instantiate it, I can only get the dialog to show if I use myClass.this from the parent class. I thought getBaseContext() did the same thing but I guess not. What am I missing?


I believe you should look here first: Diffinitive rules for using Android's getBaseContext, getApplicationContext or using an Activity's “this”


"this" refers to what method you're in, and "getBaseContext/getApplicationContext" refers to the Activity you're in.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号