Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 576
eyalb Avatar asked Aug 05 '11 06:08

eyalb


People also ask

What is activity and view in Android?

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.)

What is difference between activity and layout in Android?

Layout is where you organize the views in your page. But without activity, they have no meaning. Because in activity, you have to get these views and use them programmaticaly. All together, you load views from layout to activity and in activies you implement your whole program.

What is the difference between activity and class in Android?

Class - A class is a combination of methods, variables and data types. Every Java or Android project must have at least one class. Activity - An Activity is an android class. If we want to use an activity class, we must use extend Activity in your android project.


2 Answers

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).

like image 60
Amplify91 Avatar answered Oct 31 '22 06:10

Amplify91


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.

like image 21
Bogdan M. Avatar answered Oct 31 '22 07:10

Bogdan M.