如何进行其他活动? [英] How to access another activity?
问题描述
为了清楚起见,此不是我想要的.我想访问另一个活动的上下文.
Just to make it clear, this is not I want. I want to access another Activity's context.
假设我有两个活动,MainActivity
和WebActivity
.在MainActivity
中,我使用oAuth2
登录,登录后,我启动WebActivity
.在WebActivity
中,我需要使用功能mTencent.logout(MainActivity.this);
注销,问题是如何从WebActivity
访问MainActivity
?
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不是封闭类吗?
MainActivity is not an enclosing class?
考虑到我是android的初学者,这可能不是实现它的确切方法.
Considering I'm a starter of android, here may be not the exact way to implement it.
有人会帮忙吗?谢谢!
API:void com.tencent.tauth.Tencent.logout(Context context)
推荐答案
在login
和logout
方法中使用Application
上下文.因为它们将在应用程序级别进行管理.
Use Application
context in your login
and logout
methods. As they will be managed at Application level.
因此将mTencent.logout(MainActivity.this);
更改为mTencent.logout(getApplicationContext());
.
还更改您的login
方法以在应用程序上下文中工作.
Also change your login
method to work in application context.
这篇关于如何进行其他活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!