Calling a Service from Activity in Android

Posted by Unknown Rabu, 23 Januari 2013 0 komentar
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);
}}
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Calling a Service from Activity in Android
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke https://androidpopuler.blogspot.com/2013/01/calling-service-from-activity-in-android.html. Terima kasih sudah singgah membaca artikel ini.

0 komentar:

Posting Komentar

Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android populer.