0

everyone. I am new to android. Recently, I tried to learn how to extend Application, but there is a strange problem. I have tried a lot of methods, but still can not solve it. So, thanks in advance if anyone can help me.

The code section is like this:

package com.example.xw.myfirstapplication;

import android.app.Application;

/**
 * Created by Administrator on 2016/8/26.
 */
public class MyApplication extends Application {
    public static MyApplication mApplication;

    @Override
    public void onCreate(){
    super.onCreate();
    mApplication = this;

    }

    public static MyApplication getMyApplication(){
        return mApplication;
    }
}

And, Manifest.xml is like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.xw.myfirstapplication"
    >
    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="24" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application android:name="com.example.xw.myfirstapplication.MyApplication"

        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        >
        <!--<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>-->
        <!--<uses-permission android:name="android.permission.INTERNET"></uses-permission>-->
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--<activity android:name="testNewTech.DisplayMessageActivity" />
        <activity android:name="testNewTech.NotificationActivity"></activity>-->
    </application>

</manifest>

But, when I run the code, something happens very quickly, like this:

enter image description here

In addition: 1. I tried not to use extended Application but default Application, everything is good.

  1. I add Log.v("MainActivity", "start onCreate"); in method onCreate() of class MainActivity. But, there is nothing in logcat, so I think the method onCreate() of class MainActivity is not processed.

So, anyone has any advice? Thank you so much!

Kirkland
  • 3,257
  • 1
  • 16
  • 17
xing
  • 95
  • 1
  • 12

1 Answers1

0

If you can see in your manifest.xml file then you can pass another class

<application android:name="com.example.xw.myfirstapplication.MyApplication"
...
...
>

just change

<application android:name="com.example.xw.myfirstapplication.Application"
...
...
>
Farmer
  • 4,093
  • 3
  • 23
  • 47