Kris Roofe Kris Roofe - 10 days ago 6
Android Question

How to access another activity?

Just to make it clear, this is not I want. I want to access another Activity's context.

Suppose I've two activities,

MainActivity
and
WebActivity
. In
MainActivity
I used
oAuth2
login, and after login I start the
WebActivity
. In
WebActivity
I need to logout with the function
mTencent.logout(MainActivity.this);
, the question is how can I access
MainActivity
from
WebActivity
?


If I do this directly, I get the error,


MainActivity is not an enclosing class?


Considering I'm a starter of android, here may be not the exact way to implement it.

Will someone help? Thank you!

The API :
void com.tencent.tauth.Tencent.logout(Context context)

Answer

Use Application context in your login and logout methods. As they will be managed at Application level.

So change mTencent.logout(MainActivity.this); to mTencent.logout(getApplicationContext());.

Also change your login method to work in application context.

Comments