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:
@@ -161,6 +161,16 @@
|
||||
</intent-filter>
|
||||
</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"
|
||||
android:label="@string/soft_input_modes">
|
||||
<intent-filter>
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/activity_animation_msg"/>
|
||||
|
||||
<Button android:id="@+id/fade_animation"
|
||||
|
||||
45
samples/ApiDemos/res/layout/activity_finish_affinity.xml
Normal file
45
samples/ApiDemos/res/layout/activity_finish_affinity.xml
Normal 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>
|
||||
@@ -14,9 +14,6 @@
|
||||
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"
|
||||
@@ -24,8 +21,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/activity_recreate_msg"/>
|
||||
|
||||
<Button android:id="@+id/recreate"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/alarm_controller"/>
|
||||
|
||||
<Button android:id="@+id/one_shot"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/alarm_service"/>
|
||||
|
||||
<Button android:id="@+id/start_alarm"
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/foreground_service_controller"/>
|
||||
|
||||
<Button android:id="@+id/start_foreground"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/forward_target"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/forwarding"/>
|
||||
|
||||
<Button android:id="@+id/go"
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/intent_activity_flags"/>
|
||||
|
||||
<Button android:id="@+id/flag_activity_clear_task"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/intents"/>
|
||||
|
||||
<Button android:id="@+id/get_music"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/local_sample"/>
|
||||
|
||||
<Button android:id="@+id/go"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/local_service_binding"/>
|
||||
|
||||
<Button android:id="@+id/bind"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/local_service_controller"/>
|
||||
|
||||
<Button android:id="@+id/start"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/messenger_service_binding"/>
|
||||
|
||||
<Button android:id="@+id/bind"
|
||||
@@ -41,6 +41,7 @@
|
||||
<TextView android:id="@+id/callback"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:gravity="center_horizontal" android:paddingTop="4dip"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/redirect_enter"/>
|
||||
|
||||
<Button android:id="@+id/go"
|
||||
|
||||
@@ -23,14 +23,13 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/redirect_getter"/>
|
||||
|
||||
<EditText android:id="@+id/text"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip">
|
||||
android:layout_weight="0" android:paddingBottom="4dip">
|
||||
<requestFocus />
|
||||
</EditText>
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/redirect_main"/>
|
||||
|
||||
<TextView android:id="@+id/text"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip" />
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<Button android:id="@+id/clear"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
|
||||
@@ -23,14 +23,15 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" 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."/>
|
||||
|
||||
<TextView android:id="@+id/callback"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
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">
|
||||
<LinearLayout android:orientation="vertical"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/remote_service_binding"/>
|
||||
|
||||
<Button android:id="@+id/bind"
|
||||
@@ -46,7 +46,8 @@
|
||||
<TextView android:id="@+id/callback"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:gravity="center_horizontal" android:paddingTop="4dip"/>
|
||||
android:gravity="center_horizontal" android:paddingTop="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/remote_service_controller"/>
|
||||
|
||||
<Button android:id="@+id/start"
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/reorder_four_text"/>
|
||||
|
||||
<Button android:id="@+id/reorder_second_to_front"
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/reorder_on_launch"/>
|
||||
|
||||
<Button android:id="@+id/reorder_launch_two"
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/reorder_three_text"/>
|
||||
|
||||
<Button android:id="@+id/reorder_launch_four"
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/reorder_two_text"/>
|
||||
|
||||
<Button android:id="@+id/reorder_launch_three"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/screen_orientation_summary"/>
|
||||
|
||||
<Spinner android:id="@+id/orientation"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:paddingBottom="4dip"
|
||||
android:layout_weight="0" android:paddingBottom="4dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/service_start_arguments_controller"/>
|
||||
|
||||
<Button android:id="@+id/start1"
|
||||
|
||||
@@ -92,6 +92,8 @@
|
||||
it reconstructed with significant new changes. In this case the theme is changed.</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="pick_result">Pick a result to send, or BACK to cancel.</string>
|
||||
<string name="corky">Corky</string>
|
||||
|
||||
@@ -17,12 +17,9 @@
|
||||
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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user