views:

178

answers:

3

Is it possible to add an activity on top of the current activity. For example lets say i click a button, and then it adds a second activity to the current activity. And the second activity only covers a small place at the buttom of my current activity.

+1  A: 

The only way I know to have activities that don't take up the full screen is in a TabActivity and to make the activity a dialog. There could be others though. I'm not sure you can interact with both though.

Falmarri
+2  A: 

The activity is just displaying a window, so you can use getWindow() to modify the window params to be what we want -- wrap content instead of fill parent for example. Though for an activity that is not going to be full screen, you should first do android:theme="@android:style/Theme.Dialog" in your manifest. That by itself will make the activity look like a dialog (dialog frame and wrap content centered on the screen). You can further refine the style or layout params from there.

That said, it is important to realize that the design is that there is only one activity running at a time. So when you show this new activity, your current one will be paused. (It won't be stopped because it is still visible behind your non-fullscreen activity.) For more integrated things, just have the base activity create a Dialog and adjust its window as desired in the same way. The decision about which to use is just a matter of which is more appropriate for your design, though I think a Dialog is a far more common approach here.

hackbod
thanks, i also have to add that in order to display the second activity on top of the main one i had to use startActivityForResult to display the activity.Thanks, great answerby the way this worked for me because my second activity was more like a menu, and i didn't need to be able to interact with both activities. The second activity covers the main activity, so even if it's not paused you cannot access it.
aryaxt
A: 

I found a perfect way. In manifest change the theme to Theme.Dialog, and call the activity with startActivityForResult, this way the root activity is still there, and the new activity will show up on top of it, and it has some nice transparency as well.

aryaxt