Reputation: 5396
I have an a Java Android app that calls different activities. I thought this was how you would go about doing some object encapsulation (these three different activities show different screens but all relevant to the function of the program).
The problem I'm having is that these show up as 3 different activities on the phones. Is there anyway to encapsulate them in just one activity, or is there another method I should go about using to create multiple different screens in one app?
Thanks
Upvotes: 1
Views: 4417
Reputation: 2725
Apps are made up of different activities. Anytime you have a UI that the user can interact with, you generally have a new activity. To get from one screen to the next, you have activities that start other activities. Intents are also key because they define how an activity can be launched.
For example, in your case, the main GUI would perhaps provide a Start button. The Start button would launch the XML parsing activity. Once it completes, it would start up the map viewer activity.
What is probably happening, assuming I'm understanding your description correctly, is that you have all 3 Activities loaded in the manifest like this:
...
<activity android:name=".ExampleActivity1" android:icon="@drawable/app_icon">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ExampleActivity2" android:icon="@drawable/app_icon">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ExampleActivity3" android:icon="@drawable/app_icon">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
The element <category android:name="android.intent.category.LAUNCHER" />
means that the specified Activity can be started from the Launcher (the home screen). You will just want to put your main GUI Activity in the manifest with this intent.
The Android Developers site has a number of good resources on Activities and Intents.
Upvotes: 1
Reputation: 3122
Android will place any activity that has the following in its intent-filter
into the application launcher:
<category android:name="android.intent.category.LAUNCHER" />
Therefore, you should only define this category for your entry-point activity.
Upvotes: 3
Reputation: 3809
With Android the philosophy is one UI screen equals one activity : http://developer.android.com/guide/topics/fundamentals/activities.html
A way to have only one activity for you, would be to programmatically manage your layout : When the app is launched you fill your layout with your main GUI then you remove the views and you display your text based output finally remove this output and display your map.
For example, pseudo code :
//retrieving a layout from your main.xml
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.lila1);
//creating your mainGUI
mainLayout.addView(mainGUI);
//your main GUI actions
mainLayout.removeAllViews();
TextView tv = new TextView(this);
//computing your output and putting it in the textView
mainLayout.addView(tv);
//user reading output
mainLayout.removeAllViews();
//building your map
mainLayout.AddView(map);
Upvotes: 2
Reputation: 18489
Hoping that you want all 3 activities in one screen,I will suggest to go for fragments.You can go fragments.
http://developer.android.com/guide/topics/fundamentals/fragments.html
Upvotes: 1