Home | History | Annotate | Download | only in norestart
      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.content.Intent;
     20 import android.os.RemoteCallback;
     21 import com.android.cts.norestart.R;
     22 
     23 import android.app.Activity;
     24 import android.os.Bundle;
     25 
     26 public class NoRestartActivity extends Activity {
     27     private static int sCreateCount;
     28     private int mNewIntentCount;
     29 
     30     @Override
     31     protected void onCreate(Bundle savedInstanceState) {
     32         super.onCreate(savedInstanceState);
     33         setContentView(R.layout.no_restart_activity);
     34         sCreateCount++;
     35         final RemoteCallback callback = getIntent().getParcelableExtra("RESPONSE");
     36         sendResponse(callback);
     37     }
     38 
     39     @Override
     40     protected void onNewIntent(Intent intent) {
     41         super.onNewIntent(intent);
     42         mNewIntentCount++;
     43         final RemoteCallback callback = intent.getParcelableExtra("RESPONSE");
     44         sendResponse(callback);
     45     }
     46 
     47     private void sendResponse(RemoteCallback callback) {
     48         final Bundle payload = new Bundle();
     49         payload.putInt("CREATE_COUNT", sCreateCount);
     50         payload.putInt("NEW_INTENT_COUNT", mNewIntentCount);
     51         callback.sendResult(payload);
     52     }
     53 }
     54