Request for comment on Activity flow design

by Gavin Bong » Tue, 24 Jun 2008 16:06:59 GMT

Sponsored Links
 I have a need to intersperse the flow between one Activity to another
with an intermediate Activity.

Let's call the intermediate activity INTERMEDIATE.

So imagine my application having a normal activity flow like this:

A -> B -> C -> D

Now putting the intermediary activity into the flow, we get:


When the user presses the BACK button starting from D, it will go
directly to C.
i.e. the INTERMEDIATE activity only appears in the forward direction.

Basically INTERMEDIATE will transition between foreground & background
many times
throughout the lifetime of the app.

A summary of my requirements:

1) The INTERMEDIATE activity should NOT die unless the initial launch
activity A exits.
    i.e. I only have an "exit" menu item in A.

2) I need to be able to change the contents displayed by INTERMEDIATE
during a transition.
   i.e. From A -> B, I will need the properties of INTERMEDIATE: (2.1)
the displayed content. (2.2) the "next" activity to progress to
(activity B). This applies to the other forward transitions.

My idea:

3) Store the "states" in a service. And in INTERMEDIATE's onResume() I
can query the service
for both (2.1) and (2.2) and change it accordingly.
4) I still don't know which of the launch modes to use for
Based on the docs; it's between singleTask and singleInstance. However
I don't understand the concept of "Tasks" as described in the doc:


Only allow one instance of this activity to ever be running. This
activity gets a unique task with only itself running in it; if it is
ever launched again with the same Intent, then that task will be
brought forward and its onNewIntent(Intent) method called. If this
activity tries to start a new activity, that new activity will be
launched in a separate task.

Any help would be much appreciated.



Request for comment on Activity flow design

by Mark Murphy » Tue, 24 Jun 2008 20:42:54 GMT

 > Any help would be much appreciated.

Just because you want multiple disparate views does not mean you need 
multiple disparate activities.

For example, you could use ViewFlipper to hold A, B, C, D, and 
INTERMEDIATE as views, and flip between them as needed based on your 
business requirements.

The only absolute need for separate activities is if they need to be 
separate entry points from outside your application (e.g., the classic 

Mark Murphy (a Commons Guy) 
Warescription: All titles, revisions, & ebook formats, just $35/year


Sponsored Links

Request for comment on Activity flow design

by hackbod » Thu, 26 Jun 2008 04:59:35 GMT

 Don't use singleTask or singleInstance, because that will cause your
overall activity flow to be broken up into separate tasks for each
activity where this intermediate goes.

There really isn't a way to do exactly what you want.


Request for comment on Activity flow design

by [EMAIL PROTECTED] » Thu, 26 Jun 2008 06:53:17 GMT

 Why can't INTERMEDIATE be a part of each preceeding activity and
optionally excecuted based on state information? Or be the parent of
B, C, and D visibly present only when desired?


Other Threads

1. Scrollable Menu Bar like Fox news app

If anybody know the code for create scrollable menubar in app..
Insted of tab i want that scrollable menu


2. problem with Search suggestions

I am trying to implement search suggestions in my app in the lines of
Searchable Dictionary, except that my data comes from a Sqlite

Everything seems to be working except the suggestions. I created a
sample animal database with these values
 {"Lion", "Tiger", "Elephant", "Deer", "Kangaroo"}

Now when I start typing and click on submit button it works fine.

example typing 't' and hitting search returns the list with Tiger and
Elephant. But when showing search suggestions it seems to get the
correct number of items being returned as it shows those many rows but
it does not populate them. When I click on any of the rows I see that
its not passing selectionArgs. It is being null.

What might be causing this issue?
Here is my Database class
package com.achie.gs1;

public class SampleDatabase {

        private static final String DATABASE_NAME = "zoodatabase.db";
        private static final String ANIMALS_TABLE = "animals";
        private static final int DATABASE_VERSION = 2;

        private final ZooOpenHelper mDatabaseOpenHelper;
        private static final HashMap<String, String> mColumnMap =

        public static final String ANIMAL_NAME = "name";

        public SampleDatabase(Context context) {
                mDatabaseOpenHelper = new ZooOpenHelper(context);

        private static HashMap<String, String> buildColumnMap() {
                HashMap<String, String> map = new HashMap<String, String>();
                map.put(ANIMAL_NAME, ANIMAL_NAME);
                map.put(BaseColumns._ID, "rowid AS "+BaseColumns._ID);
                map.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID, "rowid AS
                map.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, "rowid AS

                return map;

        public Cursor getAnimal(String rowId, String[] columns) {
                String selection = "rowid = ?";
                String[] selectionArgs = new String[] {rowId};
                return query(selection, selectionArgs, columns);

        public Cursor getAnimalMatches(String query, String[] columns) {
                String selection = ANIMAL_NAME + " LIKE ?";
                String[] selectionArgs = new String[] {"%"+query+"%"};
                return query(selection, selectionArgs, columns);

        private Cursor query(String selection, String[] selectionArgs,
String[] columns) {
                SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

                Cursor cursor = 
columns, selection, selectionArgs, null, null, null);
                if(cursor == null) {
                        return null;
                } else if (!cursor.moveToFirst()) {
                        return null;
                return cursor;

        private static class ZooOpenHelper extends SQLiteOpenHelper {

                private SQLiteDatabase mDatabase;
                private static final String CREATE_ANIMALS_TABLE = "CREATE TABLE
                        " (_id integer primary key autoincrement, 
"+ANIMAL_NAME+" text not
                private static final String[] ANIMALS = new String[] {"Lion",
"Tiger", "Elephant", "Deer", "Kangaroo"};

                public ZooOpenHelper(Context context) {
                        super(context, DATABASE_NAME, null, DATABASE_VERSION);

                public void onCreate(SQLiteDatabase db) {
                        mDatabase = db;

                public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {}

                private void loadDatabase() {
                        new Thread(new Runnable() {
                                public void run() {

                private void loadAnimals() {
                        for (int i=0; i<ANIMALS.length; i++) {
                                ContentValues initialValues = new 
                                initialValues.put("name", ANIMALS[i]);
                                mDatabase.insert(ANIMALS_TABLE, null, 

Here is my content provider
package com.achie.gs1;

public class SampleProvider extends ContentProvider{

        public static String AUTHORITY = "com.achie.gs1.SampleProvider";
        public static final Uri CONTENT_URI = Uri.parse("content://"+AUTHORITY

        public static final String ANIMALS_MIME_TYPE =
        public static final String ANIMAL_ITEM_MIME_TYPE =

        private SampleDatabase mDatabase;

        private static final int GET_ANIMALS = 0;
        private static final int GET_ANIMAL_ITEM = 1;
        private static final int ANIMAL_SUGGEST = 2;
        private static final int SHORTCUT_REFRESH = 3;

        private static final UriMatcher sUriMatcher = buildUriMatcher();

        private static UriMatcher buildUriMatcher() {
                UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
                // Get animals
                matcher.addURI(AUTHORITY, "animals", GET_ANIMALS);
                matcher.addURI(AUTHORITY, "animals/#", GET_ANIMAL_ITEM);
                // To get suggestions
                matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY,
                matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY 
+ "/


                return matcher;

        public boolean onCreate() {
                mDatabase = new SampleDatabase(getContext());
                return true;

        public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
                switch(sUriMatcher.match(uri)) {
                        case ANIMAL_SUGGEST:
                                if (selectionArgs == null){
                                        throw new IllegalArgumentException(" 
selectionArgs must be
provided for the uri for suggestion at a:\n "+uri);
                                return searchAnimals(selectionArgs[0]);
                        case GET_ANIMALS:
                                if (selectionArgs == null){
                                        throw new IllegalArgumentException(" 
selectionArgs must be
provided for the uri for searching animals at a:\n "+uri);
                                return searchAnimals(selectionArgs[0]);
                        case GET_ANIMAL_ITEM:
                                return getAnimal(uri);
                        case SHORTCUT_REFRESH:
                                return refreshShortcut(uri);
                                throw new IllegalArgumentException("Unknown Uri 
at a: "+uri);

        public String getType(Uri uri) {
                switch (sUriMatcher.match(uri)) {
                        case GET_ANIMALS:
                                return ANIMALS_MIME_TYPE;
                        case GET_ANIMAL_ITEM:
                                return ANIMAL_ITEM_MIME_TYPE;
                        case ANIMAL_SUGGEST:
                                return SearchManager.SUGGEST_MIME_TYPE;
                        case SHORTCUT_REFRESH:
                                return SearchManager.SHORTCUT_MIME_TYPE;
                                throw new IllegalArgumentException("unknown Url 

        private Cursor refreshShortcut(Uri uri) {
                String rowId = uri.getLastPathSegment();
                String[] columns = new String[] {
                return mDatabase.getAnimal(rowId, columns);

        private Cursor searchAnimals(String query) {
                query = query.toLowerCase();
                String[] columns = new String[] {BaseColumns._ID,
                return mDatabase.getAnimalMatches(query, columns);

        private Cursor getAnimal(Uri uri) {
                String rowId = uri.getLastPathSegment();
                String[] columns = new String[] {SampleDatabase.ANIMAL_NAME};
                return mDatabase.getAnimal(rowId, columns);

        public int delete(Uri uri, String selection, String[] selectionArgs)
{return 0;}
        public Uri insert(Uri uri, ContentValues values) {return null;}
        public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) { return 0;     }
Thank you,


3. Rotate bitmap in opengl

4. myLocationOverlay - customizing the compass position on screen?

5. Creating Sliding Drawer in new look

6. Align Custom Dialog at the bottom of the screen

7. Google analytics install referrer problem