open alert dialog activity without opening parent activity

Viewed 117

I'm writing a program that offers a quick AlertDialog. The AlertDialog comes up by itself but the parent activity opens in tasks. The app is about receiving SMS. The user runs the app for the first time and closes it, then I start a Service and try to read received message using BroadcastReceiver and then show an AlertDialog anywhere the user is. When I call AlertDialog, parent activity starts too. I don't want the parent activity to open on its own.

This is the Android Manifest file:

    <activity android:name=".dialog"
        android:theme="@style/Theme.AppTheme.CustomTheme"
        android:launchMode="singleInstance"/>
1 Answers

You could add the AlertDialog Box at the beginning (in the onCreate method) of the code in Activity.java class.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Add the AlertDialog Box code here

    setContentView(R.layout.activity_name);
}

This will show the dialog before the Activity is initialized.

Related