I'm using job scheduler and my main activity schedules a service to start the next time there is internet connection. So when the app is first installed, the layout has just one button, when you click it, it schedules the network dependent service and then I want the activity to be finished(as in the layout to be destroyed so the user gets the screen he had before the app was installed) so I have 2 questions about that:
1) if the activity that schedules the service is destroyed does that mean that the service is still scheduled or is it lost ?
2) why does calling the method finish()
at the end of the onClick event (after scheduling the service) not finish the activity and instead nothing happens as if finish()
doesn't even exist ?
This is the OnCreate code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mJobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo.Builder builder = new JobInfo.Builder(1,
new ComponentName(getPackageName(),
JobSchedulerService.class.getName()));
builder.setPersisted(true);
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
mJobScheduler.schedule(builder.build());
}
});
}