2014-09-19 78 views
4

我有一個廣播接收器,從中調用intentservice.I想要將intentservice中接收到的數據發送到activity.String s = extras.getString(「Notice」)。我想將此收到的字符串發送到新活動將數據從意圖服務傳遞到活動

回答

1
@Override 
protected void onHandleIntent(Intent arg0) { 
    Intent dialogIntent = new Intent(getBaseContext(), myActivity.class); 
    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    dialogIntent.putExtra("value", extras.getString("Notice")); 
    getApplication().startActivity(dialogIntent); 
} 
0
public class YourIntentService extends IntentService { 

    @Override 
    protected void onHandleIntent(Intent arg0) { 
     // TODO Auto-generated method stub 
     Intent intent = new Intent(this, YourNewActivity.class); 
     intent.putExtra("YourStringKey", "yourString"); 
     startActivity(intent); 
    } 

    public YourIntentService() { 
     super("YourIntentService"); 
    } 

} 

試試這個。我爲我的誤會道歉。

+0

我想從intentservice從廣播接收器 – user3790145 2014-09-19 07:49:54

+0

將數據發送到一個activity.Not它給了一個錯誤,有些標誌是缺少 – user3790145 2014-09-19 09:24:35

+0

然後添加像'intent.addFlags該標誌(Intent.FLAG_ACTIVITY_NEW_TASK) ;' – 2014-09-19 09:26:54

0
public class MyIntentService extends IntentService { 

public MyIntentService() { 
    super(" MyIntentService"); 

} 

@Override 
protected void onHandleIntent(Intent arg0) { 
     String s=arg0.getExtras.getString("Notice") 
     Intent i = new Intent(this, yourActivity.class); 
     i.putExtra("Notice",s); 
     getApplication().startActivity(i); 
} 

}