1 /* 2 * Copyright (C) 2012 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 com.example.android.apis.app; 18 19 import com.example.android.apis.R; 20 21 import android.app.Activity; 22 import android.app.NotificationManager; 23 import android.content.Intent; 24 import android.os.Bundle; 25 import android.view.View; 26 import android.widget.Button; 27 28 /** 29 * This is an activity that provides an interstitial UI for the notification 30 * that is posted by {@link IncomingMessage}. It allows the user to switch 31 * to the app in its appropriate state if they want. 32 */ 33 public class IncomingMessageInterstitial extends Activity { 34 @Override onCreate(Bundle savedInstanceState)35 protected void onCreate(Bundle savedInstanceState) { 36 super.onCreate(savedInstanceState); 37 38 setContentView(R.layout.incoming_message_interstitial); 39 40 Button button = (Button) findViewById(R.id.notify_app); 41 button.setOnClickListener(new Button.OnClickListener() { 42 public void onClick(View v) { 43 switchToApp(); 44 } 45 }); 46 } 47 48 //BEGIN_INCLUDE(app_launch) 49 /** 50 * Perform a switch to the app. A new activity stack is started, replacing 51 * whatever is currently running, and this activity is finished. 52 */ switchToApp()53 void switchToApp() { 54 // We will launch the app showing what the user picked. In this simple 55 // example, it is just what the notification gave us. 56 CharSequence from = getIntent().getCharSequenceExtra(IncomingMessageView.KEY_FROM); 57 CharSequence msg = getIntent().getCharSequenceExtra(IncomingMessageView.KEY_MESSAGE); 58 // Build the new activity stack, launch it, and finish this UI. 59 Intent[] stack = IncomingMessage.makeMessageIntentStack(this, from, msg); 60 startActivities(stack); 61 finish(); 62 } 63 //END_INCLUDE(app_launch) 64 } 65