android - Pass data after closing acticity -
i have application need pass data (using intent maybe) broadcastreceiver
, broadcast send data service connect internet. problem want happen when close current activity! show in code: oncomplete send custome intent filter broadcastreciever.
@override public void oncompleted(int serverresponsecode, byte[] serverresponsebody) { intent = new intent().putextra("title", title).putextra("username", username).putextra("spec", new_spec).putextra("link", link).putextra("desc", desc).putextra("abstract", abstract_); i.setaction("com.omaralmrsomi.masharee3app.upload_complete_notification"); sendbroadcast(i); }
my service:
@override public int onstartcommand(intent intent, int flags, int startid) { this.ctx = this; if (intent.getdata() != null) { upload(intent.getextras().getstring("title"), intent.getextras().getstring("username"), intent.getextras().getstring("abstract"), intent.getextras().getstring("desc"), intent.getextras().getstring("link"), intent.getextras().getstring("spec")); } return super.onstartcommand(intent, flags, startid); }
broadcast receiver:
@override public void onreceive(context context, intent intent) { string username = intent.getextras().getstring("username"); string title = intent.getextras().getstring("title"); string spec = intent.getextras().getstring("spec"); string link = intent.getextras().getstring("link"); string desc = intent.getextras().getstring("desc"); string abstract_ = intent.getextras().getstring("abstract"); if (intent.getaction().equals("com.omaralmrsomi.masharee3app.upload_complete_notification")) { context.startservice(new intent(context.getapplicationcontext(), publishservice.class) .putextra("username", username) .putextra("title", title) .putextra("spec", spec) .putextra("link", link) .putextra("desc", desc) .putextra("abstract", abstract_)); } }
the problem when upload file complete call oncomplete method @ time closed activity , background service recived null.
Comments
Post a Comment