What is the difference between view and activity in android development?-ThrowExceptions

Exception or error:

When do I need to create a new activity and when do I need to change the view?

My app needs to do:

Screen #1

two big buttons(sort of menu)

Screen #2

list of items – depend on the selection on prev screen

Screen #3

another list – depend on the selection on prev screen

Screen #4

show item

All screens need to have the same menu menu (the last has another button)

Do I need to create an activity for each screen or just change the view in the same activity?

Maybe I need to create a parent class myBase that will extend activity and all my activities will extend him?

How to solve:

You should create separate activities for you screens. Android handles the back button of the device by popping the current activity out from the stack and displaying the last one. So if for example the user wants to return to screen 2 for another selection, the back button does this.

###

A View in Android is a widget that displays something. Buttons, listviews, imageviews, etc. are all subclasses of View. When you say “change view” I assume you mean change the layout by using setContentView(). This usually only needs to be done once per activity. An Activity is basically what you are referring to as a screen. To answer your question, it sounds like you need four separate activities (one for each screen).

###

The “right” way to do it is to use Activity for each screen and use the <include> tag for the menu you would like to be in all screens.

This way you will have the “back” button act as it should be and it would be easier for you to handle when switching screens.

To use the , you should put the things you want to reuse into extra files.
Then you can use it as follows:

<!-- my_header.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/text01"/>

In another file include it with:

<include layout="@layout/my_header" />
<!-- your other stuff -->

###

activity is like canvas where you put your drawing as view.Yes you can set all above four view in single activity but it will depend how you handle it and does your app needs it to be done like this.

###

View is Display System of Android where you define layout to put subclasses of View in it eg. Buttons, Images etc. But Activity is Screen System of Android where you put display as well as user-interaction,(or whatever which can be contained in full-screen Window.)

Now for your question,you are creating full window screen#2 ,screen#3… ,so it is activity.
In these screen you can define layout/or Views.

I hope it helps.

###

You should create 4 xml files… and play Around changing content using setContentView(R.Layout.yourxml);..

you can do this using single Activity.. it depends on how big the class becomes.. if its too heavy with lot of different stuff, for the sake of cohision and to avoid coupling use multiple Activities

Leave a Reply

Your email address will not be published. Required fields are marked *