1

I have the following manifest.

<application
    android:name=".MyMainApplication"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MyMainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

I also have the following global static function.

MyMainApplication application = MyMainApplication.instance();as technique described in Using Application context everywhere?

I was wondering, out from application variable, is it possible for me to get MyMainActivity?

Community
  • 1
  • 1
Cheok Yan Cheng
  • 48,324
  • 124
  • 436
  • 828

2 Answers2

1

There is no way to retrieve the application's main Activity using the Application instance.

Usually there is no reason to do this... perhaps there is a better solution than manipulating the main Activity directly as you apparently are doing. Maybe you should update your post explaining specifically what you are attempting to do.

Alex Lockwood
  • 82,434
  • 38
  • 201
  • 248
-3

You can start the activity form the MyMainApplication class though it doesn't extends Activity In Main Application Class create new Intent and set the intent flags to Intent.FLAG_ACTIVITY_NEW_TASK . Activity gets instantiated. I have tested and verified.

code snippet for reference :

Intent intent = new Intent(this,MyMainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Omid Nazifi
  • 5,205
  • 8
  • 29
  • 56
Badrinath
  • 295
  • 6
  • 24