How to start a service in Oncreate without button Onclick ,but it should be stopped using button
How to start a service in Oncreate without button Onclick ,but it should be stopped using button I am trying to play music continuously in background without any button click,it should play on launching activity,and again it can be stopped by stop button.But it is not stopping as it is placed in Oncreate() ,what can be the solution for this. Please anyone tell me how to stopservice.Thankyou in advance. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); start = findViewById(R.id.startbutton); stop = findViewById(R.id.stopbutton); Intent i = new Intent(this, Service.class); this.startService(i); stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(view.getContext(), Service.class); stopService(i); Toast.makeText(MainActivity.this, "stop service called...