tags:

views:

238

answers:

4

Is it in any way possible to launch an activity from the main function without having a UI? i.e. is there a way to create a sort of "wrapper" around another activity, i.e. by launching the main activity, it takes you to another activity automatically.

If that is not possible, is there a way to remove the main activity from the stack so that clicking the back button does not take you to a blank UI? Here's an example of what I'm trying to do:

public class WrapperActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:555-1212"));
        startActivity(intent);
    }
}
+1  A: 

You need to add the Intent flag,

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Or

call "finish();" after firing the intent.

Vishwanath
I'm not sure that the `FLAG_ACTIVITY_CLEAR_TOP` trick will work here, because the `Activity` being started will be from another application. `finish()` should definitely work, though.
CommonsWare
finish() will work.
Rajnikant
Added finish(); and Translucent.NoTitleBar to manifest. Works like a charm.
fjmustak
+1  A: 

In your manifest, when you declare the activity, use theme "@android:style/Theme.Translucent.NoTitleBar"

Ex:

<activity android:name="yourActivityName" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar">
Brian515
+1  A: 

finish(); worked for me... thanks

dev_in
A: 

Using

<activity android:name="yourActivityName" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar">

mentioned by Brian515 works great. This method is useful for creating an entry point Activity that decides on which activity to call, start, services, etc without having to show a UI to the user. Remember to use finish() after you have started your intent.

Tmac