为什么要扩展应用程序类? [英] Why extend an Application class?

查看:116
本文介绍了为什么要扩展应用程序类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要扩展一个应用程序类?

Why extend an Application class?

什么是它给我吗?

为什么要那么做?

我读到它可用于全局变量,这一切,都是其他的应用程序?

I read that it can be used to global variables, that's all, are other applications?

推荐答案

随口说说,我想不出一个真正的场景,扩展应用或者是preferable另一种方法或需要完成的东西。如果你有一个昂贵的,经常使用的对象,当您发现该对象当前没有present可以初始化它在IntentService。应用本身运行在UI线程上,而IntentService运行在自己的线程。

Offhand, I can't think of a real scenario in which extending Application is either preferable to another approach or necessary to accomplish something. If you have an expensive, frequently used object you can initialize it in an IntentService when you detect that the object isn't currently present. Application itself runs on the UI thread, while IntentService runs on its own thread.

我preFER从活动数据传递到活动有明确的意图,或使用共享preferences。也有方法可以从一个片段来使用接口其父活动传递数据。

I prefer to pass data from Activity to Activity with explicit Intents, or use SharedPreferences. There are also ways to pass data from a Fragment to its parent Activity using interfaces.

这篇关于为什么要扩展应用程序类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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