During Android development, many people use activity statck to simulate the activity stack that is invisible to the android underlying layer.
The advantages and disadvantages are not mentioned much ..
The following is an implementation.
private static Stack<Activity> s_activitiesStack = new Stack<Activity>();public final static void pushActivity(Activity activity) {if (IConfig.MANAGE_ACTIVITYSTACK_MANUALLY) {if (IConfig.DEBUG_ON)Log.v(TAG, "Push activity:" + activity.getClass().getName());s_activitiesStack.push(activity);}}public final static void popActivity() {if (IConfig.MANAGE_ACTIVITYSTACK_MANUALLY) {if (!s_activitiesStack.isEmpty()) {s_activitiesStack.pop();}}}public final static Activity getTopActivity() {if (IConfig.MANAGE_ACTIVITYSTACK_MANUALLY) {if (!s_activitiesStack.isEmpty()) {return s_activitiesStack.peek();}}return null;}public final static void backToActivity(Class activity) {if (IConfig.MANAGE_ACTIVITYSTACK_MANUALLY) {while (!s_activitiesStack.isEmpty()) {Activity a = s_activitiesStack.peek();if (a.getClass().equals(activity)|| a.getClass().equals(HomeActivity.class)) {break;}if (IConfig.DEBUG_ON)Debug.u(TAG, "a.getClass():" + a.getClass().toString());if(a instanceof HotelDetailsActivity){((HotelDetailsActivity)a).back();}else{a.finish();Utils.popActivity();}}}}public final static void exit(Context context, Class luanchActivity) {Intent intent = new Intent();intent.setClass(context, luanchActivity);intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);intent.putExtra(AppConstants.BUNDLEKEY_EXIT, true);context.startActivity(intent);}