Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen does Application's onCreate() method get called?
    primarykey
    data
    text
    <p>In my Android application, I have a <code>DefaultApplication</code> class which extends <code>android.app.Application</code>, and in its <code>onCreate()</code> I bind some services which will be used by my other Activities in this app.</p> <p>Also I have a <code>BroadcastReceiver</code> which listens and receives C2DM Messages. When this receiver receives a message when the application is not running, it will fire a dialog which shows the upcoming message and it will start an Activity of my application.</p> <p>My question is, when I start an activity without any interaction with <code>DefaultApplication</code>, will my <code>DefaultApplication</code>'s <code>onCreate()</code> get called because an Activity of that application has started?</p> <p>Here are the definition and Manifest of my <code>DefaultApplication</code>:</p> <pre><code>public class DefaultApplication extends Application { @Override public void onCreate() { super.onCreate(); doBindService(); } void doBindService() { // Establish a connection with the service. We use an explicit // class name because we want a specific service implementation that // we know will be running in our own process (and thus won't be // supporting component replacement by other applications). bindService(new Intent(DefaultApplication.this, SocketService.class), socketServiceConnection, Context.BIND_AUTO_CREATE); mIsBound = true; } void doUnbindService() { if (mIsBound) { // Detach our existing connection. unbindService(socketServiceConnection); mIsBound = false; } } } </code></pre> <p>Manifest looks like this:</p> <pre><code>&lt;application android:icon="@drawable/icon" android:label="@string/app_name" android:name="com.mypackage.DefaultApplication" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:debuggable="true"&gt; &lt;service android:name="com.mypackage.services.SocketService"&gt;&lt;/service&gt; &lt;activity android:name="TestActivity" android:screenOrientation="landscape"&gt;&lt;/activity&gt; &lt;/application&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload