如何进行其他活动? [英] How to access another activity?

查看:130
本文介绍了如何进行其他活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了清楚起见,不是我想要的.我想访问另一个活动的上下文.

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

假设我有两个活动,MainActivityWebActivity.在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)

推荐答案

loginlogout方法中使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆