Created
September 25, 2016 09:22
-
-
Save Sp4Rx/58a9c899ec838904d0a0ef52623e455f to your computer and use it in GitHub Desktop.
ServiceDemo 0.1
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.example.suvajit.servicedemopersistant; | |
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() { | |
Intent intentService = new Intent(this,BackgroundService.class); | |
startService(intentService); | |
Toast.makeText(BackgroundService.this, "Service Will Be Restarted...", Toast.LENGTH_SHORT).show(); | |
} | |
} |
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.example.suvajit.servicedemopersistant; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Intent intent = new Intent(this,BackgroundService.class); | |
startService(intent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment