Skip to content

Instantly share code, notes, and snippets.

@Shivamdhuria
Last active May 29, 2019 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shivamdhuria/934251186394ac061372b86cf7a2ddc6 to your computer and use it in GitHub Desktop.
Save Shivamdhuria/934251186394ac061372b86cf7a2ddc6 to your computer and use it in GitHub Desktop.
public class MainActivity extends AppCompatActivity {
private Button startServiceButton;
private Button stopServiceButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startServiceButton = findViewById(R.id.start_button);
stopServiceButton = findViewById(R.id.stop_button);
startServiceButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startService(new Intent(v.getContext(), ForegroundService.class));
}
});
stopServiceButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stopService(new Intent(v.getContext(), ForegroundService.class));
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment