簡體   English   中英

從服務呼叫活動時出錯

[英]Error While Calling Activity from Service

我已經編寫了用於從服務中調用活動的服務類代碼。.但是它不起作用.....請幫助我.......

public class MyService extends Service {
private static final String TAG = "MyService";
MediaPlayer player;
Uri u1 ;

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    Intent intent = null;
    int startId = 0;
    super.onStart(intent, startId);
    Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
    Log.d(TAG, "onCreate");

//Intent i=new Intent(MyService.this,CustomDialogExample.class);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//startActivity(i);

}   


//player = MediaPlayer.create(this, u1.parse("http://marakana.com/static/tut/braincandy.m4a")); 
//      player.setLooping(false); // Set looping
//      player.setLooping(false); // Set looping
//  

@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) {

    Intent i=new Intent().setClass(MyService.this,CustomDialogExample.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(i);
    Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
    Log.d(TAG, "onStart");
    //player.start();
}
  }

Intent Intent = null; ... super.onStart(intent,...);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM