Skip to content

Instantly share code, notes, and snippets.

@codesteps
Last active October 28, 2018 04:41
package com.codesteps.david.startup;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import java.io.Console;
import java.util.Random;
import android.widget.Toast;
public class MyService extends Service {
public MyService() {
}
// MyService holds these messages to deliver when requested
//
private final String[] m_Messages = {"Hello, World!", "Good Morning!", "Good Evening!", "Good Night to All!"};
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "onStartCommand - Service Started", Toast.LENGTH_SHORT).show();
return Service.START_STICKY;
}
@Override
public void onCreate() {
}
@Override
public void onDestroy() {
Toast.makeText(this, "onDestroy - Service Stopped", Toast.LENGTH_SHORT).show();
}
// Return the random message
//
public String getMessage() {
Random rand = new Random();
return m_Messages[rand.nextInt(4)];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment