-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.java
34 lines (32 loc) · 1.18 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.example.zz.servicethatstartsitself;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
/**
* Create by Zolboo Erdenebaatar 08/31/2018
* Here's the entry point for the application.
* On this activity, we have a single button thats
* only purpose is to start the service that is not
* to be stopped.
*/
public class MainActivity extends AppCompatActivity {
Button startButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startButton= (Button) findViewById(R.id.startButton);
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent= new Intent(getApplicationContext(), TypicalService.class);
//We start the service here.
startService(intent);
Log.d(this.getClass().getSimpleName(), "Service has started from the MainActivity");
}
});
}
}