Reputation: 27
Hi In my app i have two activities. one is the main activity. so when i launch the app it invokes the main activity. the main activity displays on the top left corner of the screen with some width and height. on the main activity there is a button. when i press the button it launches the second activity. when the second activity is launched it displays itself in the center of the screen. When second activity got the focus, the first activity goes to the pause state but it is still displayed on the screen. But when i move from the second activity to the first activity, the first activity gains focus. The problem is when the first activity gains focus, the second activity disappears from the screen. What i want is it should not disappear. It has to be on the screen in pause state. Then I need to switch between these activities.
The following is my manifest file:-
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:theme="@android:style/Theme.Dialog"
android:name="com.example.firstapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:theme="@android:style/Theme.Dialog"
android:name="com.example.firstapp.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.example.firstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.firstapp.MainActivity" />
</activity>
</application>
The two actions uses Linear layout as their root layout and contains some gui elemnts.
Upvotes: 0
Views: 107
Reputation: 133560
Use fragments. http://developer.android.com/guide/components/fragments.html
Example at the developer site.
http://developer.android.com/guide/components/fragments.html#Example
EDIT:
When you h navigate to second Activity from first activity, first activity will be paused (will be there on back stack).Your second activity is put on stack and takes focus. When you return to first activity second activity is popped form the stack and destroyed. Now first activity takes focus. This is how it works. Stack works like last in, first out. (LIFO).
For more detail regarding activity back stack read the topic in the link below.
http://developer.android.com/guide/components/tasks-and-back-stack.html
Upvotes: 1
Reputation: 12823
You need to use Fragments. Vogella has a fantastic tutorial.
http://www.vogella.com/articles/AndroidFragments/article.html
Upvotes: 1