Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Add API demo for running multiple foreground services.
Browse files Browse the repository at this point in the history
Change-Id: I44435f6e7750ccbbadf5e293dd10069c6cef94a4
  • Loading branch information
Dianne Hackborn committed Aug 2, 2016
1 parent 644dd1a commit 9302998
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions samples/ApiDemos/AndroidManifest.xml
Expand Up @@ -595,6 +595,7 @@
</activity>

<service android:name=".app.ForegroundService" />
<service android:name=".app.ForegroundService2" />

<activity android:name=".app.ForegroundService$Controller"
android:label="@string/activity_foreground_service_controller"
Expand Down
14 changes: 11 additions & 3 deletions samples/ApiDemos/res/layout/foreground_service_controller.xml
Expand Up @@ -37,25 +37,33 @@
<Button android:id="@+id/start_foreground_wakelock"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/start_service_foreground_wakelock">
<requestFocus />
</Button>

<Button android:id="@+id/start_background"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/start_service_background">
<requestFocus />
</Button>

<Button android:id="@+id/start_background_wakelock"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/start_service_background_wakelock">
<requestFocus />
</Button>

<Button android:id="@+id/stop"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/stop_service">
</Button>

<Button android:id="@+id/start_foreground_2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/start_service_foreground_2">
</Button>

<Button android:id="@+id/stop_2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/stop_service_2">
</Button>

</LinearLayout>

1 change: 1 addition & 0 deletions samples/ApiDemos/res/values/strings.xml
Expand Up @@ -312,6 +312,7 @@
<string name="start_service_foreground_wakelock">Start Service Foreground w/Wakelock</string>
<string name="start_service_background">Start Service Background</string>
<string name="start_service_background_wakelock">Start Service Background w/Wakelock</string>
<string name="start_service_foreground_2">Start Service Foreground 2</string>

<string name="activity_isolated_service_controller">App/Service/Isolated Service Controller</string>
<string name="isolated_service_controller">This demonstrates the use of android:isolatedProcess
Expand Down
Expand Up @@ -259,6 +259,10 @@ protected void onCreate(Bundle savedInstanceState) {
button.setOnClickListener(mBackgroundWakelockListener);
button = (Button)findViewById(R.id.stop);
button.setOnClickListener(mStopListener);
button = (Button)findViewById(R.id.start_foreground_2);
button.setOnClickListener(mForegroundListener2);
button = (Button)findViewById(R.id.stop_2);
button.setOnClickListener(mStopListener2);
}

private OnClickListener mForegroundListener = new OnClickListener() {
Expand Down Expand Up @@ -299,5 +303,21 @@ public void onClick(View v) {
ForegroundService.class));
}
};

private OnClickListener mForegroundListener2 = new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(ForegroundService.ACTION_FOREGROUND);
intent.setClass(Controller.this, ForegroundService2.class);
startService(intent);
}
};

private OnClickListener mStopListener2 = new OnClickListener() {
public void onClick(View v) {
stopService(new Intent(Controller.this,
ForegroundService2.class));
}
};

}
}
@@ -0,0 +1,20 @@
/*
* Copyright (C) 2016 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;

public class ForegroundService2 extends ForegroundService {
}

0 comments on commit 9302998

Please sign in to comment.