Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start activity without showing it

I have an activity A, which starts activity B and activity B starts activity C. Is there a way not to show activity B. I want this behavour because if there is no content (eg for ListView) for activity B, show activity C on which I select some data, and then press back button to go back to activity B. The point is that I would like to have activity B on activity stack, but not to show it in certain cases.

like image 907
Matjaz Kristl Avatar asked Dec 20 '11 07:12

Matjaz Kristl


2 Answers

I found the solution:

  • Activity A starts activity B with extra parameter (intent.putExtra("something", true))
  • Activity B:
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getIntent().hasExtra("something") && getIntent().getBooleanExtra("something", false) {
            //show activity B
        setContentView(R.layout.activity_B);
    } else {
            //don't show activity B, start activity C
        startActivityForResult(activity_C, ACTIVITY_NOT_INITIALIZED); //start activity C
    }
}

//when came back from activity C, check if activity B was already initialized

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ACTIVITY_NOT_INITIALIZED) {
        //show activity B
        setContentView(R.layout.activity_B);
  }
}
like image 104
Matjaz Kristl Avatar answered Oct 21 '22 19:10

Matjaz Kristl


In your manifest set

android:theme="@android:style/Theme.NoDisplay"

for your activity.

like image 42
Omid Omidi Avatar answered Oct 21 '22 18:10

Omid Omidi