Add API demo for Activity.finishAffinity().

Also fix text on some of the existing demos to use the nice
larger font.

Change-Id: I90d3815cd47cda08217cfc6307d64942f6750ae2
This commit is contained in:
Dianne Hackborn
2012-04-26 18:57:13 -07:00
parent 791babeffc
commit 9cd165488b
30 changed files with 176 additions and 60 deletions

View File

@@ -161,6 +161,16 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".app.FinishAffinity"
android:label="@string/activity_finish_affinity"
android:taskAffinity=":finishing"
android:enabled="@bool/atLeastJellyBean">
<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>

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/activity_animation_msg"/> android:text="@string/activity_animation_msg"/>
<Button android:id="@+id/fade_animation" <Button android:id="@+id/fade_animation"

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 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.
-->
<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:textAppearance="?android:attr/textAppearanceMedium"
android:text="No matter how deep you go, Activity.finishAffinity() will get you back."/>
<TextView android:id="@+id/seq"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:paddingBottom="4dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button android:id="@+id/nest"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Nest some more">
<requestFocus />
</Button>
<Button android:id="@+id/finish"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="FINISH!">
<requestFocus />
</Button>
</LinearLayout>

View File

@@ -14,9 +14,6 @@
limitations under the License. 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" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:padding="4dip" android:orientation="vertical" android:padding="4dip"
android:gravity="center_horizontal" android:gravity="center_horizontal"
@@ -24,8 +21,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/activity_recreate_msg"/> android:text="@string/activity_recreate_msg"/>
<Button android:id="@+id/recreate" <Button android:id="@+id/recreate"

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/alarm_controller"/> android:text="@string/alarm_controller"/>
<Button android:id="@+id/one_shot" <Button android:id="@+id/one_shot"

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/alarm_service"/> android:text="@string/alarm_service"/>
<Button android:id="@+id/start_alarm" <Button android:id="@+id/start_alarm"

View File

@@ -24,8 +24,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/foreground_service_controller"/> android:text="@string/foreground_service_controller"/>
<Button android:id="@+id/start_foreground" <Button android:id="@+id/start_foreground"

View File

@@ -24,6 +24,7 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/forward_target"/> android:text="@string/forward_target"/>
</LinearLayout> </LinearLayout>

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/forwarding"/> android:text="@string/forwarding"/>
<Button android:id="@+id/go" <Button android:id="@+id/go"

View File

@@ -24,8 +24,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/intent_activity_flags"/> android:text="@string/intent_activity_flags"/>
<Button android:id="@+id/flag_activity_clear_task" <Button android:id="@+id/flag_activity_clear_task"

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/intents"/> android:text="@string/intents"/>
<Button android:id="@+id/get_music" <Button android:id="@+id/get_music"

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/local_sample"/> android:text="@string/local_sample"/>
<Button android:id="@+id/go" <Button android:id="@+id/go"

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/local_service_binding"/> android:text="@string/local_service_binding"/>
<Button android:id="@+id/bind" <Button android:id="@+id/bind"

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/local_service_controller"/> android:text="@string/local_service_controller"/>
<Button android:id="@+id/start" <Button android:id="@+id/start"

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/messenger_service_binding"/> android:text="@string/messenger_service_binding"/>
<Button android:id="@+id/bind" <Button android:id="@+id/bind"
@@ -41,6 +41,7 @@
<TextView android:id="@+id/callback" <TextView android:id="@+id/callback"
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center_horizontal" android:paddingTop="4dip"/> android:gravity="center_horizontal" android:paddingTop="4dip"/>
</LinearLayout> </LinearLayout>

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/redirect_enter"/> android:text="@string/redirect_enter"/>
<Button android:id="@+id/go" <Button android:id="@+id/go"

View File

@@ -23,14 +23,13 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/redirect_getter"/> android:text="@string/redirect_getter"/>
<EditText android:id="@+id/text" <EditText android:id="@+id/text"
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip">
android:paddingBottom="4dip">
<requestFocus /> <requestFocus />
</EditText> </EditText>

View File

@@ -23,14 +23,14 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/redirect_main"/> android:text="@string/redirect_main"/>
<TextView android:id="@+id/text" <TextView android:id="@+id/text"
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" /> android:textAppearance="?android:attr/textAppearanceMedium" />
<Button android:id="@+id/clear" <Button android:id="@+id/clear"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_height="wrap_content"

View File

@@ -23,14 +23,15 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Demonstrates various options that can be used when binding to a service to modify its process management."/> android:text="Demonstrates various options that can be used when binding to a service to modify its process management."/>
<TextView android:id="@+id/callback" <TextView android:id="@+id/callback"
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0"
android:gravity="center_horizontal" android:paddingBottom="4dip"/> android:gravity="center_horizontal" android:paddingBottom="4dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:orientation="vertical" <LinearLayout android:orientation="vertical"

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/remote_service_binding"/> android:text="@string/remote_service_binding"/>
<Button android:id="@+id/bind" <Button android:id="@+id/bind"
@@ -46,7 +46,8 @@
<TextView android:id="@+id/callback" <TextView android:id="@+id/callback"
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0"
android:gravity="center_horizontal" android:paddingTop="4dip"/> android:gravity="center_horizontal" android:paddingTop="4dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout> </LinearLayout>

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/remote_service_controller"/> android:text="@string/remote_service_controller"/>
<Button android:id="@+id/start" <Button android:id="@+id/start"

View File

@@ -26,8 +26,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/reorder_four_text"/> android:text="@string/reorder_four_text"/>
<Button android:id="@+id/reorder_second_to_front" <Button android:id="@+id/reorder_second_to_front"

View File

@@ -26,8 +26,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/reorder_on_launch"/> android:text="@string/reorder_on_launch"/>
<Button android:id="@+id/reorder_launch_two" <Button android:id="@+id/reorder_launch_two"

View File

@@ -26,8 +26,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/reorder_three_text"/> android:text="@string/reorder_three_text"/>
<Button android:id="@+id/reorder_launch_four" <Button android:id="@+id/reorder_launch_four"

View File

@@ -26,8 +26,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/reorder_two_text"/> android:text="@string/reorder_two_text"/>
<Button android:id="@+id/reorder_launch_three" <Button android:id="@+id/reorder_launch_three"

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/screen_orientation_summary"/> android:text="@string/screen_orientation_summary"/>
<Spinner android:id="@+id/orientation" <Spinner android:id="@+id/orientation"

View File

@@ -23,8 +23,8 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0" android:paddingBottom="4dip"
android:paddingBottom="4dip" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/service_start_arguments_controller"/> android:text="@string/service_start_arguments_controller"/>
<Button android:id="@+id/start1" <Button android:id="@+id/start1"

View File

@@ -92,6 +92,8 @@
it reconstructed with significant new changes. In this case the theme is changed.</string> it reconstructed with significant new changes. In this case the theme is changed.</string>
<string name="recreate">Recreate</string> <string name="recreate">Recreate</string>
<string name="activity_finish_affinity">App/Activity/Finish Affinity</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>

View File

@@ -17,12 +17,9 @@
package com.example.android.apis.app; package com.example.android.apis.app;
import com.example.android.apis.R; import com.example.android.apis.R;
import com.example.android.apis.app.LocalServiceActivities.Controller;
import android.app.Activity; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2012 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 android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class FinishAffinity extends Activity {
int mNesting;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_finish_affinity);
mNesting = getIntent().getIntExtra("nesting", 1);
((TextView)findViewById(R.id.seq)).setText("Current nesting: " + mNesting);
// Watch for button clicks.
Button button = (Button)findViewById(R.id.nest);
button.setOnClickListener(mNestListener);
button = (Button)findViewById(R.id.finish);
button.setOnClickListener(mFinishListener);
}
private OnClickListener mNestListener = new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(FinishAffinity.this, FinishAffinity.class);
intent.putExtra("nesting", mNesting+1);
startActivity(intent);
}
};
private OnClickListener mFinishListener = new OnClickListener() {
public void onClick(View v) {
finishAffinity();
}
};
}