could anyone please tell me what's the difference between getApplicationContext() and MyActivity.this.."MyActivity" being a class that extends Activity class..somethimes getApplicationContext() doesn't work and I need to use MyActivity.this when the constructur asks for a context...
for example, if i use ProgressDialog p=new ProgressDialog(getApplicationContext());
it gives an error
however, if i use ProgressDialog p=new ProgressDialog(MyActivity.this);
it runs fine
cool_zephyr
7
Junior Poster in Training
Recommended Answers
Jump to PostApplication context
getApplicationContext()
is different then View contextgetContext
or as in your caseMyActivity.class
(both means same). Real difference in usage is only what part of lifecycle of the activity or whole application you will be affecting with whatever you about to do.So if you need a context …
All 4 Replies
peter_budo
2,532
Code tags enforcer
Team Colleague
Featured Poster
cool_zephyr
7
Junior Poster in Training
peter_budo
2,532
Code tags enforcer
Team Colleague
Featured Poster
cool_zephyr
7
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.