Thursday 15 January 2015

Retrieve calling Activity from Intent in Android -



Retrieve calling Activity from Intent in Android -

i trying pass along activity pointer in intent don't know how retrieve it.

i have calling activity (myactivity) next snippet of code:

intent myserviceintent = new intent(this, myservice.class); startservice(myserviceintent);

in service class want retrieve calling activity. this:

private activity currentactivity = null; public int onstartcommand(intent intent, int flags, int startid) { currentactivity = (currentactivity) intent.getclass(); homecoming super.onstartcommand(intent, flags, startid); }

this doesn't work don't know does. couldn't find putextra takes activity parameter. how can this?

in first activity take static activity variable this,

public static activity activity;

in oncreate this.

activity = this;

then in sec activity this,

activity activity = (your activity name).activity;

this best solution according little knowledge. pass code/value varification this.

intent intent = new intent(); intent.putextra("somevalue", "data");

and in sec activity check value, if value required value required activity instance. hope solve problem , if will, please allow me know.

android android-intent android-activity android-service

No comments:

Post a Comment