Skip to content Skip to sidebar Skip to footer

Is It Safe To Use Mainactivity.this

Is it safe to use MainActivity.this in anonymous class when starting a new Activity, please check the code below. I used to create an init a variable of Activity type, but this app

Solution 1:

Of-course it is safe as you can see this in API demos and sample code. it works fine I never encounter any problem.

Solution 2:

Yes, this is the standard approach to refer to the current activity instance from within an inner class.

Post a Comment for "Is It Safe To Use Mainactivity.this"