API demo for new Activity.recreate() API.
Change-Id: I56bd36edf2cd5cd9b6f95dd4a2b82571689c04d2
This commit is contained in:
@@ -151,6 +151,14 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".app.ActivityRecreate"
|
||||||
|
android:label="@string/activity_recreate">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".app.SoftInputModes"
|
<activity android:name=".app.SoftInputModes"
|
||||||
android:label="@string/soft_input_modes">
|
android:label="@string/soft_input_modes">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
37
samples/ApiDemos/res/layout/activity_recreate.xml
Normal file
37
samples/ApiDemos/res/layout/activity_recreate.xml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Demonstrates starting and stopping a local service.
|
||||||
|
See corresponding Java code com.android.sdk.app.LocalSerice.java. -->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical" android:padding="4dip"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:paddingBottom="4dip"
|
||||||
|
android:text="@string/activity_recreate_msg"/>
|
||||||
|
|
||||||
|
<Button android:id="@+id/recreate"
|
||||||
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:text="@string/recreate">
|
||||||
|
<requestFocus />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -80,6 +80,11 @@
|
|||||||
<string name="activity_persistent">App/Activity/Persistent State</string>
|
<string name="activity_persistent">App/Activity/Persistent State</string>
|
||||||
<string name="persistent_msg">Demonstration of persistent activity state with getPreferences(0).edit() and getPreferences(0).</string>
|
<string name="persistent_msg">Demonstration of persistent activity state with getPreferences(0).edit() and getPreferences(0).</string>
|
||||||
|
|
||||||
|
<string name="activity_recreate">App/Activity/Recreate</string>
|
||||||
|
<string name="activity_recreate_msg">Demonstration recreating an activity, to have
|
||||||
|
it reconstructed with significant new changes. In this case the theme is changed.</string>
|
||||||
|
<string name="recreate">Recreate</string>
|
||||||
|
|
||||||
<string name="activity_receive_result">App/Activity/Receive Result</string>
|
<string name="activity_receive_result">App/Activity/Receive Result</string>
|
||||||
<string name="pick_result">Pick a result to send, or BACK to cancel.</string>
|
<string name="pick_result">Pick a result to send, or BACK to cancel.</string>
|
||||||
<string name="corky">Corky</string>
|
<string name="corky">Corky</string>
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.android.apis.app;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
import com.example.android.apis.app.LocalServiceActivities.Controller;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
public class ActivityRecreate extends Activity {
|
||||||
|
int mCurTheme;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
mCurTheme = savedInstanceState.getInt("theme");
|
||||||
|
|
||||||
|
// Switch to a new theme different from last theme.
|
||||||
|
switch (mCurTheme) {
|
||||||
|
case android.R.style.Theme_Holo_Light:
|
||||||
|
mCurTheme = android.R.style.Theme_Holo_Dialog;
|
||||||
|
break;
|
||||||
|
case android.R.style.Theme_Holo_Dialog:
|
||||||
|
mCurTheme = android.R.style.Theme_Holo;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mCurTheme = android.R.style.Theme_Holo_Light;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
setTheme(mCurTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
setContentView(R.layout.activity_recreate);
|
||||||
|
|
||||||
|
// Watch for button clicks.
|
||||||
|
Button button = (Button)findViewById(R.id.recreate);
|
||||||
|
button.setOnClickListener(mRecreateListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(Bundle savedInstanceState) {
|
||||||
|
super.onSaveInstanceState(savedInstanceState);
|
||||||
|
savedInstanceState.putInt("theme", mCurTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OnClickListener mRecreateListener = new OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
recreate();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user