The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
| 19 | import java.util.HashMap; |
| 20 | |
| 21 | import android.content.Intent; |
| 22 | import android.os.Bundle; |
| 23 | import android.util.Log; |
| 24 | |
| 25 | /** |
| 26 | * A screen that contains and runs multiple embedded activities. |
| 27 | */ |
| 28 | public class ActivityGroup extends Activity { |
| 29 | private static final String TAG = "ActivityGroup"; |
| 30 | private static final String STATES_KEY = "android:states"; |
| 31 | static final String PARENT_NON_CONFIG_INSTANCE_KEY = "android:parent_non_config_instance"; |
| 32 | |
| 33 | /** |
| 34 | * This field should be made private, so it is hidden from the SDK. |
| 35 | * {@hide} |
| 36 | */ |
| 37 | protected LocalActivityManager mLocalActivityManager; |
| 38 | |
| 39 | public ActivityGroup() { |
| 40 | this(true); |
| 41 | } |
| 42 | |
| 43 | public ActivityGroup(boolean singleActivityMode) { |
| 44 | mLocalActivityManager = new LocalActivityManager(this, singleActivityMode); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | protected void onCreate(Bundle savedInstanceState) { |
| 49 | super.onCreate(savedInstanceState); |
| 50 | Bundle states = savedInstanceState != null |
| 51 | ? (Bundle) savedInstanceState.getBundle(STATES_KEY) : null; |
| 52 | mLocalActivityManager.dispatchCreate(states); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected void onResume() { |
| 57 | super.onResume(); |
| 58 | mLocalActivityManager.dispatchResume(); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | protected void onSaveInstanceState(Bundle outState) { |
| 63 | super.onSaveInstanceState(outState); |
| 64 | Bundle state = mLocalActivityManager.saveInstanceState(); |
| 65 | if (state != null) { |
| 66 | outState.putBundle(STATES_KEY, state); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | protected void onPause() { |
| 72 | super.onPause(); |
| 73 | mLocalActivityManager.dispatchPause(isFinishing()); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | protected void onStop() { |
| 78 | super.onStop(); |
| 79 | mLocalActivityManager.dispatchStop(); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | protected void onDestroy() { |
| 84 | super.onDestroy(); |
| 85 | mLocalActivityManager.dispatchDestroy(isFinishing()); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Returns a HashMap mapping from child activity ids to the return values |
| 90 | * from calls to their onRetainNonConfigurationInstance methods. |
| 91 | * |
| 92 | * {@hide} |
| 93 | */ |
| 94 | @Override |
| 95 | public HashMap<String,Object> onRetainNonConfigurationChildInstances() { |
| 96 | return mLocalActivityManager.dispatchRetainNonConfigurationInstance(); |
| 97 | } |
| 98 | |
| 99 | public Activity getCurrentActivity() { |
| 100 | return mLocalActivityManager.getCurrentActivity(); |
| 101 | } |
| 102 | |
| 103 | public final LocalActivityManager getLocalActivityManager() { |
| 104 | return mLocalActivityManager; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | void dispatchActivityResult(String who, int requestCode, int resultCode, |
| 109 | Intent data) { |
| 110 | if (who != null) { |
| 111 | Activity act = mLocalActivityManager.getActivity(who); |
| 112 | /* |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 113 | if (false) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | TAG, "Dispatching result: who=" + who + ", reqCode=" + requestCode |
| 115 | + ", resCode=" + resultCode + ", data=" + data |
| 116 | + ", rec=" + rec); |
| 117 | */ |
| 118 | if (act != null) { |
| 119 | act.onActivityResult(requestCode, resultCode, data); |
| 120 | return; |
| 121 | } |
| 122 | } |
| 123 | super.dispatchActivityResult(who, requestCode, resultCode, data); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | |