Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.suvajit.servicedemo;
- import android.app.Service;
- import android.content.Intent;
- import android.os.IBinder;
- import android.support.annotation.Nullable;
- import android.widget.Toast;
- public class BackgroundService extends Service {
- @Nullable
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- Toast.makeText(BackgroundService.this, "Service Started...", Toast.LENGTH_SHORT).show();
- return START_STICKY;
- }
- @Override
- public void onDestroy() {
- // Removed the restart service from onDestroy
- Toast.makeText(BackgroundService.this, "Service is Stopping...", Toast.LENGTH_SHORT).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement