1 /* 2 * Copyright (C) 2018 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.server.wm.app; 18 19 import static android.server.wm.app.Components.LaunchingActivity.KEY_FINISH_BEFORE_LAUNCH; 20 21 import android.app.Activity; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.server.wm.ActivityLauncher; 25 import android.server.wm.CommandSession; 26 27 /** 28 * Activity that launches another activities when new intent is received. 29 */ 30 public class LaunchingActivity extends Activity { 31 @Override onCreate(Bundle savedInstanceState)32 protected void onCreate(Bundle savedInstanceState) { 33 super.onCreate(savedInstanceState); 34 35 final Intent intent = getIntent(); 36 if (intent != null && intent.getExtras() != null 37 && intent.getExtras().getBoolean(KEY_FINISH_BEFORE_LAUNCH)) { 38 finish(); 39 } 40 if (savedInstanceState == null && intent != null) { 41 launchActivityFromExtras(intent.getExtras()); 42 } 43 } 44 45 @Override onNewIntent(Intent intent)46 protected void onNewIntent(Intent intent) { 47 super.onNewIntent(intent); 48 launchActivityFromExtras(intent.getExtras()); 49 } 50 launchActivityFromExtras(Bundle extras)51 private void launchActivityFromExtras(Bundle extras) { 52 ActivityLauncher.launchActivityFromExtras( 53 this, extras, CommandSession.handleForward(extras)); 54 } 55 } 56 57