1 /* 2 * Copyright (C) 2016 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.android.cts.norestart; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.content.res.Resources; 22 import android.os.Bundle; 23 24 public class NoRestartActivity extends Activity { 25 private final static String RESOURCE_ID = 26 "com.android.cts.norestart.feature:string/no_restart_feature_text"; 27 28 private int mCreateCount; 29 private int mNewIntentCount; 30 31 @Override onCreate(Bundle savedInstanceState)32 protected void onCreate(Bundle savedInstanceState) { 33 super.onCreate(savedInstanceState); 34 setContentView(R.layout.no_restart_activity); 35 mCreateCount++; 36 sendBroadcast(); 37 } 38 39 @Override onNewIntent(Intent intent)40 protected void onNewIntent(Intent intent) { 41 super.onNewIntent(intent); 42 mNewIntentCount++; 43 sendBroadcast(); 44 } 45 sendBroadcast()46 private void sendBroadcast() { 47 final Intent intent = new Intent("com.android.cts.norestart.BROADCAST"); 48 intent.putExtra("CREATE_COUNT", mCreateCount); 49 intent.putExtra("NEW_INTENT_COUNT", mNewIntentCount); 50 intent.putExtra("RESOURCE_CONTENT", getResourceInFeature()); 51 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); 52 sendBroadcast(intent); 53 } 54 getResourceInFeature()55 private String getResourceInFeature() { 56 final Resources res = getResources(); 57 final int resId = res.getIdentifier(RESOURCE_ID, null, null); 58 if (resId == 0) { 59 return null; 60 } 61 return res.getString(resId); 62 } 63 } 64