16
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Applicationクラスを使ってみる

Last updated at Posted at 2016-09-29

Applicationクラスを継承したクラスを作成

MainApplication.java
public class MainApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        Log.d("TAG", "hello");
    }
}

AndroidManifestファイルに一行追記

Applicationクラスを使うにはAndroidManifest.xmlにクラス名を追記することで、アプリ起動時に自動的にインスタンス化される

android:name=".MainApplication"を追加

AndroidManifest.xml
    <application
        
        android:name=".MainApplication"
        
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
16
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?