/MyService.java Secret
Last active
October 28, 2018 04:41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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