保证应用程序类定义的启动接收器被调用之前被实例化 [英] Is the Application class guaranteed to be instantiated before a defined boot receiver is called

查看:337
本文介绍了保证应用程序类定义的启动接收器被调用之前被实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅我这样一个基本问题。据我所知,我的应用程序的过程开始时,应用程序类实例化,我知道当手机开机完成我的引导接收器将被调用。我假设,因为电话可以通过我的应用程序拥有BOOT_COMPLETED意图过滤舱单知道,重启过程。手机重新启动,手机开始与BOOT_COMPLETED所有进程,电话打完BOOT_COMPLETED播出。我担心的是来自如果我引用我的启动接收器内的应用类的实例变量,如果被实例化我的应用程序课前接收器将永远被调用疑惑。

Excuse me for such an elementary question. I understand that the Application class is instantiated when my app's process starts and I understand when the phone is completed booting my boot receiver will be called. I'm assuming since the phone knows via the manifest that my app holds BOOT_COMPLETED intent filter, the reboot process is. Phone reboots, phone starts all processes with BOOT_COMPLETED, phone fires off BOOT_COMPLETED broadcast. My concern came from wondering if I reference Application class instance variables within my boot receiver if the receiver would ever get called before my Application class was instantiated.

再原谅我,如果这是死了明显。我从来没有完全理解的重启机制。

Again excuse me if this is dead obvious. I've never fully understood the reboot mechanics.

推荐答案

这是应用程序总是前任何活动/服务/接收器的启动。下面是细谈一对夫妇的博客:

An Application is always started before any of its Activities/Services/Receivers. Here are a couple of blogs that go into the details:

  • http://multi-core-dump.blogspot.com/2010/04/android-application-launch.html
  • http://multi-core-dump.blogspot.com/2010/04/android-application-launch-part-2.html

不过,根据@CommansWare评论:

But, according to a comment by @CommansWare:

根据记录,之后创建的ContentProvider实例
  应用程序的实例。然而,的onCreate(的)
  ContentProvider的是应用程序的onCreate()之前调用。

Based on logging, the instance of the ContentProvider is created after the instance of the Application. However, onCreate() of the ContentProvider is called before onCreate() of the Application.

因此​​,它可能不是安全的尝试中使用的应用程序实例提供者的的onCreate()

So, it is probably not safe to try to use the Application instance within a provider's onCreate().

这篇关于保证应用程序类定义的启动接收器被调用之前被实例化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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