Advertisement
Guest User

main activity

a guest
Mar 18th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. package com.gorsek.filip.services;
  2.  
  3. import android.content.Intent;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.Button;
  8.  
  9. public class MainActivity extends AppCompatActivity {
  10.  
  11.  
  12.     public static final String TASK_COUNT = "task_count";
  13.     private Button bStartService;
  14.     private Button bStopService;
  15.     private Button bStartIntentService;
  16.  
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.activity_main);
  21.  
  22.         initWidgets();
  23.         setupListeners();
  24.  
  25.  
  26.     }
  27.  
  28.     private void initWidgets() {
  29.         bStartService = findViewById(R.id.bStartService);
  30.         bStopService = findViewById(R.id.bStopService);
  31.         bStartIntentService = findViewById(R.id.bStartIntentService);
  32.     }
  33.  
  34.     private void setupListeners() {
  35.  
  36.         bStartService.setOnClickListener(new View.OnClickListener() {
  37.             @Override
  38.             public void onClick(View v) {
  39.  
  40.                 Intent intent = new Intent(MainActivity.this, MyService.class);
  41.                 startService(intent);
  42.  
  43.             }
  44.         });
  45.  
  46.         bStopService.setOnClickListener(new View.OnClickListener() {
  47.             @Override
  48.             public void onClick(View v) {
  49.                 Intent intent = new Intent(MainActivity.this, MyService.class);
  50.                 stopService(intent);
  51.  
  52.             }
  53.         });
  54.  
  55.         bStartIntentService.setOnClickListener(new View.OnClickListener() {
  56.             @Override
  57.             public void onClick(View v) {
  58.                 Intent intent = new Intent(MainActivity.this, MyIntentService.class);
  59.                 intent.putExtra(TASK_COUNT, 5);
  60.                 startService(intent);
  61.             }
  62.         });
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement