How can we call an activity through service in android???
Posted
by Shalini Singh
on Stack Overflow
See other posts from Stack Overflow
or by Shalini Singh
Published on 2010-03-30T09:49:45Z
Indexed on
2010/03/30
9:53 UTC
Read the original article
Hit count: 353
android
Hi! friends, i am a android developer,,, want to know is it possible to call an activity through background service in android like : import android.app.Service; import android.content.Intent; import android.content.SharedPreferences; import android.media.MediaPlayer; import android.os.Handler; import android.os.IBinder; import android.os.Message;
public class background extends Service{
private int timer1; @Override public void onCreate() { // TODO Auto-generated method stub super.onCreate();
SharedPreferences preferences = getSharedPreferences("SaveTime", MODE_PRIVATE); timer1 = preferences.getInt("time", 0); startservice(); }
@Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; }
private void startservice() {
Handler handler = new Handler(); handler.postDelayed(new Runnable(){ public void run() { mediaPlayerPlay.sendEmptyMessage(0); } }, timer1*60*1000); }
private Handler mediaPlayerPlay = new Handler(){
@Override public void handleMessage(Message msg) { try { getApplication(); MediaPlayer mp = new MediaPlayer();
mp = MediaPlayer.create(background.this, R.raw.alarm);
mp.start();
} catch(Exception e) { e.printStackTrace(); } super.handleMessage(msg); } };
/* * (non-Javadoc) * * @see android.app.Service#onDestroy() */ @Override public void onDestroy() { // TODO Auto-generated method stub
super.onDestroy(); } }
i want to call my activity......
© Stack Overflow or respective owner