如何从活动通过上下文活动?

编程入门 行业动态 更新时间:2024-10-27 00:28:48
本文介绍了如何从活动通过上下文活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个主要活动,并召唤其他活动来显示一些数据。

I have a main activity, and it summons another activity to display some data.

我有我整个的主要活动code。使用专用数据库辅助对象。有没有一种方法,以我的主要活动范围内传递给我的子活动在一个优雅的方式? (即从子类,像 getCallingActivityContext())

I have a private database helper object that I use throughout the main activity code. Is there a way to pass the context of my main activity to my sub activity in an elegant way? (ie, from subclass, something like getCallingActivityContext())

我总是可以创建新的数据库辅助对象。

I could always create new database helper objects.

推荐答案

扩展应用程序类可以帮助你允许申报/访问全局变量。您可以设置从任何活动的变量的ApplicationContext 和其他活动访问它,而无需使用包。

Extending the Application class helps you to allow declare/access global variables. You can set your variables from any activity to ApplicationContext and access it from other activity without using bundle.

Android的:?如何声明全局变量会帮你

更多推荐

如何从活动通过上下文活动?

本文发布于:2023-11-23 02:20:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619727.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!