Add API demo for running multiple foreground services.
Change-Id: I44435f6e7750ccbbadf5e293dd10069c6cef94a4
This commit is contained in:
@@ -259,6 +259,10 @@ public class ForegroundService extends Service {
|
||||
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() {
|
||||
@@ -299,5 +303,21 @@ public class ForegroundService extends Service {
|
||||
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