从服务调用活动时出错

时间:2011-03-16 05:26:47

标签: android

我已经编写了这个服务类代码,用于从服务中调用活动..但它不起作用.....请帮助我.......

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();
}
  }

1 个答案:

答案 0 :(得分:0)

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