Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between 'this' , 'activityname.this' and getAplicationContext()

I dont know difference between them, I sometimes use this, sometimes activityame.this, sometimes getAplicationContext() when android needs context passed.

like image 344
katsu Avatar asked Dec 26 '22 13:12

katsu


1 Answers

  • this points to the current object. In this case, an Activity Object
  • ActivityName.this also points to the current Activity Object, use it when you are working with an dynamic inner class, such as instantiating a new onClickListener() {}.
  • getApplicationContext() gets the Context reference for the whole application. Activity is a Context subclass, but certain things may vary between the appliation Context and the Activity. For the most part though, using the Activity as the Context works fine, I haven't coded anything that needs getApplicationContext() yet.
like image 169
A--C Avatar answered Mar 11 '23 03:03

A--C