简体   繁体   中英

Managing multiple activities in android application

I have an android application with many activities. I render next activity from the previous by creating an Intent object right in its code. I think this kind of code sucks. Are there any "good" ways to implement activities management in the application, best practices?

Actually, there are some standard practices that we android developer follows:

  1. Create DashBoard and start activities based on the particular dashboard option click
  2. Follow Tab-bar design

About Dashboard:

在此输入图像描述

You can get the example for Dashboard from here .

About TabBar: Why i prefer Dashboard as compared to Tabbar? Just because it is really very much easy to implement activity management in dashboard while in tab layout we have to implement ActivityGroup concept and really very much hard to handle as compared to Dashboard layout.

Activities in Android are designed to be very decoupled from each other. This is partially apparent by the idea of launching an activity with an 'intent'. It doesn't even sound specific.

If you're uncomfortable with this paradigm you can look into using Fragments or ActivityGroups . And though I wouldn't normally recommend this, you could write your own Activity Manager that wraps the Intents and makes launching and managing activities a little more explicit.

In the past, I had an app that had 4 views that I wanted to be able to cycle through:

[Back to C]<->D<->A<->B<->C<->[Next to D]

I should point out that each of the 4 activities had a common title bar control that had next/prev buttons on it.

I made a class called ActivityOrderer that had a static list of Class and two functions, next and prev. For example, next did this:

public static Class<?> nextActivityClass(Class<?> current) {
    int currentIndex = _orderedActivities.indexOf(current);
    int nextIndex = (currentIndex + 1) % _orderedActivities.size();
    return _orderedActivities.get(nextIndex);
}

Now, each Activity I created would just call set the TitleBar's next and prev buttons to start the Intent created like:

_titleBar.setNextIntent(new Intent(this, ActivityOrderer.nextActivityClass(getClass())));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM