2014-09-19 50 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); 
} 

}