Design question: Activity per screen or not

by David Melgar » Wed, 03 Feb 2010 05:23:31 GMT

Sponsored Links
 tt>Are there guidelines to help understand how fine grained to make  

I've heard people state that an activity should be just one screen and
that multi-screen applications should have one activity per screen.
But this model can seem awkward, more work, and I'm not sure what
value you get in return.

What are the pros and cons of many activites vs few.

I've also heard debate about how much processing can occur in an
activity and some people suggesting that any complex work should occur
in a service. That doesn't seem obvious to me. How is the browser
implemented? A bunch of activities and a service to do the real work,
or just one actiity to render a web page and that activity does all
the work?

Are there issues with threads that determines how you should design
you app, ie few or many activities and need for a service?


Sent from my iPhone

On Feb 2, 2010, at 9:43 AM,

Today's Topic Summary

[1 Update]

'drawable' vs. 'drawable-hdpi' in Online Tutorial [5 Updates]
list view button error [2 Updates]
Eclipse can't seem to locate [1 Update]
Bug in SDK Manager: cannot update [1 Update]
Not able to start Call Log Activity [1 Update]
SDK Setup.exe not working [1 Update]
No market on HTC hero [1 Update]
I have note pad where are notepads files saved??? [1 Update]
Can't create new class in Eclipse (Google Map View official
tutorial) [1 Update]

alagmy <> Feb 02 06:28AM -0800 ^

open all blocked sites now for free and have fun

Topic: 'drawable' vs. 'drawable-hdpi' in Online Tutorial
Indicator Veritatis <> Feb 01 12:17PM -0800 ^

It seems the online tutorials have not been rewritten to reflect
Android 2.1. For they still refer to 'drawable' and 'res/drawable',
but when I create a new project for 2.1 using the wizard, I do not GET
any such directory. Instead, I get 'res/drawable-hdpi', 'res/drawable-
ldpi' and 'res/drawable-mdpi'.

Now for some tutorials, I have been able to get by by putting files in
'res/drawable-hdpi'. But for the TabLayout tutorial,

this does not work. I still get the error message (on completion of
step 3) "R.drawable.ic_tab_artists cannot be resolved".

The files "ic_tab_artists_grey.png" and "ic_tab_artists_whit.png"
really are in res/drawable-hdpi.

I also tried changing the name 'drawable' to 'drawable-hdpi', but Java
did not like the '-' in the name (no surprise).

So how are we supposed to get this to work? Go back to 1.5? Surely
there is a better way.

Just for clarity's sake, the line of code I get the error on is: spec
= tabHost.newTabSpec("artists").setIndicator("Artists",
// res.getDrawable


Design question: Activity per screen or not

by Smelly Eddie » Wed, 03 Feb 2010 22:52:27 GMT

 avid - a few thoughts.

Each screen should be a new activity. The cost of creating a new
class is about 2 minutes and 4kb. The benefits are numerous.
1) Rely on xml layouts without custom if this screen than that or if
that screen then this
2) Avoid complex logic and bloated classes. In programming each class
should do one thing, and do it well. Android follwos this principle.
3) Navigationis handled by Android. Users can navigate back and forth
using the framework, so you don't need to code the "where am I" stuff.

A properly designed application with numerous tasks can be smaller
than a bloated activity serving many screens with unnecessary logic.
This means it also relioes on android optimized code for smoother

In regards to a service. They should be for something that is long
running, behind the scenes (like gathering twiiter updates every 10
minuites, or checking email servers). For most "complex" tasks within
an application you'll likely just use ASyncTask that will run the
logic in a background thread so the UI remains snappy.

There are more guidlines very well documentwed in the android devloper
site. UI Guidelines and Activity Flows should be researched.

On Feb 2, 3:44pm, David Melgar <> wrote:
> >

Sponsored Links

Other Threads

1. jpg images noisy on sdcard but fine in gallery, only on Android 1.6 (1.5 is fine)

In my application users take photos with an Activity that implements
SurfaceHolder.Callback. The uri.toString() is then passed as an extra
to a subsequent Activity that displays the image. All fine, except for
in Android 1.6 the jpgs on the sdcard have a strange noise when
looking at them through mac finder or win explorer after mounting the
sdcard. The images have purple and yellow stripes on their upper half.
Fine on camera gallery.

Here's some (hopefully) relevant code.

The fact that it works on 1.5 and not 1.6 points to some underlying
problems..? Is this a known issue?

private OnClickListener shutterListener = new OnClickListener() {
        public void onClick(View v) {
                ImageCaptureCallback iccb = null;
                filename = System.currentTimeMillis()+"";
                        ContentValues values = new ContentValues();
                        values.put(Media.TITLE, filename);
                        values.put(Media.DESCRIPTION, "my_photos");
                uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
                try {
                        iccb = new ImageCaptureCallback( getContentResolver
                } catch (FileNotFoundException ce) {Log.e(getClass
                //take the pic
                camera.takePicture(mShutterCallback, mPictureCallbackRaw,


public class ImageCaptureCallback implements PictureCallback  {

                private OutputStream filoutputStream;
                public ImageCaptureCallback(OutputStream filoutputStream) {
                        this.filoutputStream = filoutputStream;

                public void onPictureTaken(byte[] data, Camera camera) {

                        try {

                        } catch(Exception ex) {

protected void startNextActivity() {
                Log.d("CameraActivity","starting next activity...");
                startActivity( new Intent(CameraActivity.this,
ImageAccepter.class).putExtra("pic", uri.toString()));



2. Why app still runs during a long-press on the power key (or end call key)?

I recently ran into the same problem while writing a game except that
I noticed it for long pressing the home key. For that it looks like
onPause doesn't get called, but onWindowFocusChanged with an argument
of false does. If the user presses back from the dialog then you get
onWindowFocusChanged with an argument of true and onUserInteraction
called. Long pressing the end call button probably behaves similarly.


3. Activity [sometimes] throws Wrong state class exception when being resumed after kill

4. Google Sky Map does not show stars or constellations on my Cliq

5. opencore/progressive download : how does it work ?

6. inputbox text validation

7. Ask rom amon ra