Android Multi-Screen Application

♀尐吖头ヾ 提交于 2019-12-05 07:02:33
Tommy

What you need to do is, create a new Activity and add it to the AndroidManifest.xml:

<activity android:name="ActivityClassName" android:label="Label for the Activity"></activity>

and can be called in a method:

public void startActivity() {
    Intent someName = new Intent(CurrentClass.this, ActivityClassName.class);
    startActivity(someName);
}

Android applications generally use a separate Activity for each screen, and switch between them using Activity.startActivity and Activity.startActivityForResult. You can pass arbitrary data to an Activity via Intent.putExtra.

Hope this helps,

Phil Lello

It really depends on how you want your application to flow.

Let's consider the scenario where a user does the following:

  1. Starts your first activity
  2. Presses the 2nd tab
  3. Presses the 3rd tab
  4. Presses the back button

If you use a separate activity for each screen, then the following would happen

  1. Activity 1 is started
  2. Activity 2 is started
  3. Activity 3 is started
  4. Activity 3 is closed, user returns to Activity 2

(in this case pressing the back button again would you take you back to Activity 1, and pressing it again would exit your application)

If you used one activity for all the tabs, then the following would occur

  1. Activity 1 is started
  2. Activity 1 sets tab content to tab 2 content
  3. Activity 1 sets tab content to tab 3 content
  4. Activity 1 is closed, user returns to home screen

If you are using a screen with tabs, then the second method (a single Activity with a TabHost or similar) is the preferred method, otherwise the user will end up making a large activity-stack just switching between tabs (meaning if they switch between tabs a lot they'll have to press the back button a lot of times to exit).

If you want to go for the single activity approach, then do some research on TabHost and TabContentFactory. In the createTabContent method of your factory you can inflate a View/layout from XML to set as the tab content using View.inflate. Look those up and come back ask another question if you get stuck ;)

i think you may want to play with more than one activity.... you can have multiple activities and one xml for each of them... in this way you can have different screens... check these links. Multiple Activities, Creating an Activity.... hope this helps...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!