简体   繁体   中英

Passing data from intent service to activity

我有一个广播接收器从中调用intentservice.I想要将intentservice中收到的数据发送到activity.String s = extras.getString(“Notice”)。我想将这个收到的字符串发送到一个新的活动

@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);
}   
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");
    }

}

Try this. Sorry for misunderstanding.

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM