Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gorsek.filip.services;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- public class MainActivity extends AppCompatActivity {
- public static final String TASK_COUNT = "task_count";
- private Button bStartService;
- private Button bStopService;
- private Button bStartIntentService;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- initWidgets();
- setupListeners();
- }
- private void initWidgets() {
- bStartService = findViewById(R.id.bStartService);
- bStopService = findViewById(R.id.bStopService);
- bStartIntentService = findViewById(R.id.bStartIntentService);
- }
- private void setupListeners() {
- bStartService.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(MainActivity.this, MyService.class);
- startService(intent);
- }
- });
- bStopService.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(MainActivity.this, MyService.class);
- stopService(intent);
- }
- });
- bStartIntentService.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(MainActivity.this, MyIntentService.class);
- intent.putExtra(TASK_COUNT, 5);
- startService(intent);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement