获取上下文的Andr​​oid? [英] Get context in Android?

查看:103
本文介绍了获取上下文的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个类中我的Andr​​oid应用程序里面,我怎么能得到这些应用程序的主要内容和活动?

I am inside a class inside my android app, how can I get the apps main context and activity?

感谢您的帮助!

推荐答案

如果它是一个自定义视图:有一个paramater背景下这是你的活动

If it's a custom view: there is a paramater context which is your activity.

Activity activity = (Activity)context;

如果这是一个不同的类只是把活动的constrctor。

If it's a different class just send the activity in the constrctor.

这篇关于获取上下文的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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