Add API demo for running multiple foreground services.
Change-Id: I44435f6e7750ccbbadf5e293dd10069c6cef94a4
This commit is contained in:
@@ -595,6 +595,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service android:name=".app.ForegroundService" />
|
<service android:name=".app.ForegroundService" />
|
||||||
|
<service android:name=".app.ForegroundService2" />
|
||||||
|
|
||||||
<activity android:name=".app.ForegroundService$Controller"
|
<activity android:name=".app.ForegroundService$Controller"
|
||||||
android:label="@string/activity_foreground_service_controller"
|
android:label="@string/activity_foreground_service_controller"
|
||||||
|
|||||||
@@ -37,19 +37,16 @@
|
|||||||
<Button android:id="@+id/start_foreground_wakelock"
|
<Button android:id="@+id/start_foreground_wakelock"
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
android:text="@string/start_service_foreground_wakelock">
|
android:text="@string/start_service_foreground_wakelock">
|
||||||
<requestFocus />
|
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button android:id="@+id/start_background"
|
<Button android:id="@+id/start_background"
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
android:text="@string/start_service_background">
|
android:text="@string/start_service_background">
|
||||||
<requestFocus />
|
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button android:id="@+id/start_background_wakelock"
|
<Button android:id="@+id/start_background_wakelock"
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
android:text="@string/start_service_background_wakelock">
|
android:text="@string/start_service_background_wakelock">
|
||||||
<requestFocus />
|
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button android:id="@+id/stop"
|
<Button android:id="@+id/stop"
|
||||||
@@ -57,5 +54,16 @@
|
|||||||
android:text="@string/stop_service">
|
android:text="@string/stop_service">
|
||||||
</Button>
|
</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>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -312,6 +312,7 @@
|
|||||||
<string name="start_service_foreground_wakelock">Start Service Foreground w/Wakelock</string>
|
<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">Start Service Background</string>
|
||||||
<string name="start_service_background_wakelock">Start Service Background w/Wakelock</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="activity_isolated_service_controller">App/Service/Isolated Service Controller</string>
|
||||||
<string name="isolated_service_controller">This demonstrates the use of android:isolatedProcess
|
<string name="isolated_service_controller">This demonstrates the use of android:isolatedProcess
|
||||||
|
|||||||
@@ -259,6 +259,10 @@ public class ForegroundService extends Service {
|
|||||||
button.setOnClickListener(mBackgroundWakelockListener);
|
button.setOnClickListener(mBackgroundWakelockListener);
|
||||||
button = (Button)findViewById(R.id.stop);
|
button = (Button)findViewById(R.id.stop);
|
||||||
button.setOnClickListener(mStopListener);
|
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() {
|
private OnClickListener mForegroundListener = new OnClickListener() {
|
||||||
@@ -299,5 +303,21 @@ public class ForegroundService extends Service {
|
|||||||
ForegroundService.class));
|
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 {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user