Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android best practice - views/activities

Just starting out on android developing. To start off, I'm building an app which is gonna function like a gallery+image viewer, with the added functionality of quickly and swiftly moving pictures into subfolders, for easy sorting of lots of pictures.

So far I have 2 activites - a full screen image view, and a full screen thumbnail grid (for multiselect purposes).

Now as I'm new at this, I was wondering if this dual-activity was a wise decision. Would it be better to simply switch between content views than to power up an entirely different activity when switching from image view to grid view (and vice versa).

What I'm looking for are of course the obvious pros and cons - performance, ease and usability. But also if there are more fundamental "pattern"/best practice reasons for one or the other.

Thanks

like image 433
Dynde Avatar asked Nov 11 '11 10:11

Dynde


People also ask

What do you mean by Android activities and views?

Android App Development for BeginnersAn activity represents a single screen with a user interface just like window or frame of Java. Android activity is the subclass of ContextThemeWrapper class.

Is activity a view in Android?

There are only two hard things in Computer Science: cache invalidation and naming things.

What should be Android main activity?

Typically, one activity in an app is specified as the main activity, which is the first screen to appear when the user launches the app. Each activity can then start another activity in order to perform different actions.

How do I optimize custom view?

To speed up your view, eliminate unnecessary code from routines that are called frequently. Start by working on onDraw() , which will give you the biggest payback. In particular you should eliminate allocations in onDraw() , because allocations may lead to a garbage collection that would cause a stutter.


2 Answers

I think your dual activity approach is sensible. Generally speaking the Android Activity/View APIs are structured around having a single fixed View per Activity. Although you can manipulate Views within your Activity's layout, I'd suggest this should be restricted to hiding/showing/moving Views rather than replacing the layout wholesale.

What you probably should consider is the newer Fragments API. This can almost be though of as "activities within activities". A Fragment essentially allows you to wrap up an element of a UI (layout and behaviour) in a reusable component. So in your specific example, the two distinct UIs could be Fragments within a single activity.

This has a couple of benefits such as being able to reuse your UIs in other activities and you can do funky transition animations.

like image 110
tomtheguvnor Avatar answered Sep 18 '22 03:09

tomtheguvnor


dual activity should work, as you won't be bothered by implementing the back button action.

like image 38
josephus Avatar answered Sep 22 '22 03:09

josephus