dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' } public class MyService extends LifecycleService { @Override public void onCreate() { super.onCreate(); } @Override public void onDestroy() { super.onDestroy(); } private void startForegroundService() { Notification notification = createNotification(); startForeground(1, notification); } private void stopForegroundService() { stopForeground(true); stopSelf(); } private void startBackgroundTask() { } private void stopBackgroundTask() { } private Notification createNotification() { } } <service android:name=".MyService" android:exported="false" />


上一篇:
下一篇:
切换中文