0

In my activity I want to start a class which extends an AndroidApplication class but I don't know how to do it. I want to call the onCreate method of the AndroidApplication class, of course.

public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle bundle)
{
    super.onCreate(bundle);
    setContentView(R.layout.layout);
    new AndroidLauncher();
}
}  

Here is the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.utente.morramongame"
      android:versionCode="1"
      android:versionName="1.0">

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="25"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/GdxTheme">

    <application
        android:name=".AndroidLauncher">
    </application>

    <activity
        android:name=".MainActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:label="@string/app_name"
        android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

</application>

Tosch
  • 17
  • 4
  • register it in manifest application tag – Pavneet_Singh Jun 11 '17 at 17:03
  • @Pavneet_Singh and then? – Tosch Jun 11 '17 at 17:05
  • `onCreate` is automatically called if you set the Application up correctly – OneCricketeer Jun 11 '17 at 17:09
  • `Application` is created by the framework. You never create it or any other Android component yourself. – Kevin Krumwiede Jun 11 '17 at 17:10
  • Also see: [Why create an Application class](https://stackoverflow.com/questions/18002227/why-extend-an-application-class) – OneCricketeer Jun 11 '17 at 17:10
  • @cricket_007 should I define it as an activity in the manifest too? – Tosch Jun 11 '17 at 17:10
  • No, it's an `application`. You already have a tag for that around all your activities. That other post clearly explains what to do. Also, the description in the documentation. https://developer.android.com/reference/android/app/Application.html – OneCricketeer Jun 11 '17 at 17:12
  • @cricket_007 I posted the manifest – Tosch Jun 11 '17 at 17:14
  • I'm not sure what you want me to say. I will edit the other post. – OneCricketeer Jun 11 '17 at 17:15
  • @cricket_007 I did it but all the things in Application class aren't called – Tosch Jun 11 '17 at 17:26
  • If you put `android:name` within the ` – OneCricketeer Jun 11 '17 at 17:28
  • remove nested `application` tag and add `android:name=".AndroidLauncher"` after `android:label="@string/app_name"` – Pavneet_Singh Jun 11 '17 at 17:58
  • @Pavneet_Singh I have this error: AndroidLauncher isn't assignable to Android.app.Application – Tosch Jun 11 '17 at 18:03
  • http://androidexample.com/Global_Variable_Or_Application_Context_Variable_-_Android_Example/index.php?view=article_discription&aid=114 – Pavneet_Singh Jun 11 '17 at 18:05
  • @Pavneet_Singh my class doesn't extend Application but AndroidApplication – Tosch Jun 11 '17 at 18:07
  • @cricket_007 see – Tosch Jun 11 '17 at 18:12
  • @cricket_007 I was talking about AndroidApplication not Application, they are very different and so it isn't duplicate. I solved the problem with this question https://stackoverflow.com/questions/10711995/libgdx-inside-android-activity – Tosch Jun 11 '17 at 20:44
  • And why not? Even the answer there says *The issue was that I hadn't declared my "Bobble" class/file in the AndroidManifest file* – OneCricketeer Jun 12 '17 at 00:11
  • If you had defined [**AndroidApplication**](https://github.com/libgdx/libgdx/blob/master/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplication.java#L61) more clearly, then, I would not have closed. I apologize. It **is** an activity, so, yes it would need an `` tag, but besides that point, you have an error with the XML shown here. It is ` – OneCricketeer Jun 12 '17 at 00:14

0 Answers0