This is a service class:
public class serv extends Service {
private static final String TAG = "MyService";
AlertDialog alertDialog
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
public void onCreate() {
Toast.makeText(getApplicationContext(), "My Service Created",Toast.LENGTH_LONG).show();
}
@Override
public void onDestroy() {
Toast.makeText(this, "My Service Stopped",Toast.LENGTH_LONG).show();
Log.d(TAG, "onDestroy");
//player.stop();
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "My Service Started",Toast.LENGTH_LONG).show();
Log.d(TAG, "onStart");
//player.start();
}
}
Call service from activity:
public class MainActivity extends Activity {
private static final String TAG = "ServicesDemo";
Button buttonStart, buttonStop;
PendingIntent pendingIntent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i;
i=new Intent(MainActivity.this,serv.class);
startService(i);
}}
Comments
Post a Comment