Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch an Activity without a UI?

Tags:

android

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);     } } 
like image 802
fjmustak Avatar asked Apr 24 '10 10:04

fjmustak


People also ask

Is it possible to have activity without UI?

Explanation. Generally, every activity is having its UI(Layout). But if a developer wants to create an activity without UI, he can do it.

Can an activity start itself Android?

Yes it is. If your requirement are like that then there is no harm in doing that.

How do you create an instance of an activity?

Activity instances are always created by the Android system. This is because a lot of initializations have to be done for the activity to work. To create a new activity you call startActivity with an Intent describing the activity to start. To add more to this answer.


2 Answers

Android also provides a theme specifically for this:

android:theme="@android:style/Theme.NoDisplay" 
like image 100
Justin Avatar answered Sep 21 '22 03:09

Justin


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"> 
like image 40
strange quark Avatar answered Sep 19 '22 03:09

strange quark