chili
chili

Reputation: 3

Question about the android .finish() method

whats the difference between MyActivity.finish() and MyActivty.this.finish()? I see an example where MyActivty.this.finish() is called from hitting the OK button on a dialog asking if you want to exit the app. isn't the ".this" part redundant?

Upvotes: 0

Views: 1183

Answers (1)

Erich Douglass
Erich Douglass

Reputation: 52002

MyActivity.finish() assumes that finish() is a static method on MyActivity.

MyActivity.this.finish() is calling finish() on the enclosing instance of MyActivity. It's also equivalent to this.finish() or just finish() (assuming it's being called from within MyActivity).

Upvotes: 1

Related Questions