开发者

android asynTask to activity problem ?

I develop an GPS app. my app have a service that responsible to send GPS to server through server....

Service -----> AysncTask(sendServer)
// then in service i broadcast some variable

myFilteredResponse = new Intent(GPS_FILTER);
        myFilteredResponse.putExtra("latitude",      Double.valueOf(twoFormat.format(location.getLatitude())));
        myFilteredResponse.putExtra("longitude", Double.valueOf(twoFormat.format(location.getLongitude())));
        myFilteredResponse开发者_如何学编程.putExtra("network", MyGPS.cur_network_status);

then in my Activity I create a broadcast receiver to receive all these variable n it works fine, my UI then will change when we have new lat n lon

in my AysncTask when send to server i will get the location identify by server so i want to update my UI interface so i 1 2 use broadcast as well but it's not work !

structure

                                  broadcast
service ( on location changed ) ------------->   UI interface

            broadcast??
AsyncTask ------------->   UI interface

i can't use sendBroadcast in my AsyncTask since my AsyncTask is not activity any Idea?


i guess you problem is to get the data from the service.

you can bind the service to the UI and call the service from within the activity.

here is an opensource project. Link.

this is the service code. Link.

this is the UI. Link

EDIT: if you want to do UI updates using AsyncTask then you can use onPostExecute which runs in UI thread.

EDIT: Here you go. AsyncTask Example. Link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜