Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is the code sample for Service </p> <pre><code> package com.test.examppplee; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.widget.Toast; public class LocationService extends Service{ @Override public void onCreate() { Toast.makeText(getApplicationContext(), "onCreate", Toast.LENGTH_LONG).show(); super.onCreate(); } @Override public void onDestroy() { Toast.makeText(getApplicationContext(), "onDestroy", Toast.LENGTH_LONG).show(); super.onDestroy(); } @Override public void onStart(Intent intent, int startId) { Toast.makeText(getApplicationContext(), "onStart", Toast.LENGTH_LONG).show(); super.onStart(intent, startId); } @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } } package com.test.examppplee; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); startService(new Intent(getApplicationContext(), LocationService.class)); } public void finish(View v){ finish(); } public void start(View v){ startActivity(new Intent(getApplicationContext(), ServiceTestActivity.class)); } } package com.test.examppplee; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; public class ServiceTestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void finish(View v){ finish(); } public void start(View v){ startActivity(new Intent(getApplicationContext(), ServiceTestActivity2.class)); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload