package androidemu.app;

import java.util.Stack;

import androidemu.content.Intent;

public class ActivityManager {
	public static Stack<Activity> activityStack = new Stack<Activity>();

	public static void startActivity(Intent intent, Integer requestCode) {
		if (!activityStack.empty()) {
			Activity currentActivity = activityStack.peek();
			currentActivity.hideMenu();
			currentActivity.onPause();
		}

		activityStack.push(intent.activity);
		intent.activity.requestCode = requestCode;
		intent.activity.onCreate(null);
		intent.activity.onResume();
		intent.activity.showMenu();
	}

	public static void finish() {
		Activity closingActivity = activityStack.pop();
		closingActivity.hideMenu();
		closingActivity.onPause();
		closingActivity.onDestroy();
		Integer requestCode = closingActivity.requestCode;

		Activity resumedActivity = activityStack.peek();
		if (requestCode != null) {
			resumedActivity.onActivityResult(requestCode, closingActivity.resultCode, closingActivity.resultData);
		}
		resumedActivity.onResume();
		resumedActivity.showMenu();
	}

}

@@ -82,108 +82,711 @@
 t;%0A%0A
-public class ActivityManager %7B%0A%09public static Stack%3CActivity%3E activityStack = new Stack%3CActivity%3E();
+import com.google.gwt.event.logical.shared.ValueChangeEvent;%0Aimport com.google.gwt.event.logical.shared.ValueChangeHandler;%0Aimport com.google.gwt.user.client.History;%0A%0Apublic class ActivityManager %7B%0A%09public static Stack%3CActivity%3E activityStack = new Stack%3CActivity%3E();%0A%0A%09static %7B%0A%09%09History.addValueChangeHandler(new ValueChangeHandler%3CString%3E() %7B%0A%0A%09%09%09@Override%0A%09%09%09public void onValueChange(ValueChangeEvent%3CString%3E event) %7B%0A%09%09%09%09// We manage only back press%0A%09%09%09%09if (activityStack.size() %3E 1) %7B%0A%09%09%09%09%09// If is back, must match the previous activity in the stack%0A%09%09%09%09%09if (event.getValue().equals(activityStack.get(activityStack.size() - 2).getClass().getName())) %7B%0A%09%09%09%09%09%09finish();%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D);%0A%09%7D
 %0A%0A%09p
@@ -1005,16 +1005,99 @@
 );%0A%09%09%7D%0A%0A
+%09%09// Save browser history%0A%09%09History.newItem(intent.activity.getClass().getName());%0A
 %09%09activi

Manage Back press