Android: calling a method from a Service to an Activity -


i have simple question solve, not sure how it.

i have class extends service runs thread looking tcp connection. if 1 comes in, read input message.

if input message "start", start activity, in fashion:

intent dialogintent = new intent(getbasecontext(), voipcall.class); dialogintent.addflags(intent.flag_activity_new_task); dialogintent.putextra("inetaddress", clientsocket.getinetaddress()); getapplication().startactivity(dialogintent); 

while activity running, service keeps running. @ point may reserve "stop". call method in created activity not sure how interact it.

i not want use static method. how can please that?

thank much,

edit: changed code this:

intent dialogintent = new intent("com.voip.rudy.start_call"); dialogintent.addflags(intent.flag_activity_new_task); dialogintent.addflags(intent.flag_activity_single_top); dialogintent.addflags(intent.flag_activity_reorder_to_front); dialogintent.putextra("inetaddress", clientsocket.getinetaddress()); getapplication().startactivity(dialogintent); 

and in manifest:

<activity android:name=".voipcall">     <intent-filter>         <action android:name="com.voip.rudy.start_call" />         <action android:name="com.voip.rudy.stop_call" />         <category android:name="android.intent.category.default" />     </intent-filter> </activity>   <category android:name="android.intent.category.default" /> required avoid having crash. 

edit:

the solution given has fixed issue wanted act on member variables on class, initialized. call constructor, go activity , act on member variables.

the member variables not initialized when call 1 action after another, seems create new activity somehow. there anyway act on same activity, , keep objects intact please?

james

add intent.flag_activity_single_top | intent.flag_activity_reorder_to_front flags intent , call startactivity new action or special can identify intent.

in activity, write method called :

private void handleintent(intent intent) { } 

call oncreate (or onresume) using:

handleintent(getintent()); 

and write:

@override protected void onnewintent(intent intent) {     setintent(intent);     handleintent(intent); } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -