2011-03-16 82 views
0

活動我已經寫了服務類的此代碼從service..but它不是作品.....請幫我叫活動.......錯誤同時呼籲從服務

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

我發生以下錯誤.....無法啓動活動ComponentInfo {com.example/com.example.CustomDialogExample}:java.lang.NullPointerException – Smith 2011-03-16 05:29:35

回答

0

意圖intent = null; ... super.onStart(intent,...);

+0

嗨....我應該寫在那裏超級。 onStart(),我不知道實際..請告訴我...我不知道什麼參數通過....幫助我 – Smith 2011-03-16 05:43:13

+0

我已經從Oncreate()方法中刪除它.... BT仍然不工作... ..請幫幫我... – Smith 2011-03-16 05:58:08

相關問題