0

So i have a background service which gets location updates and I want to access the service from my tabActivity. (The method is static)

Can you tell me how to achieve that ? if i try xxxService.yyyMethod() it is not working.

I am talking about a background service started by the activity, then the activity was closed by the user and restarted. The service was bound to the same activity and also start() (so it continues to exist even after activity is closed). By not working I mean the method is not returning anything While it is supposed to. Also, any statements after the method call doesnt execute. – Ishwar 27 secs ago edit

In the activity: Bounding: *

mConnection = new ServiceConnection() {    
            public void onServiceConnected(ComponentName className, IBinder service) {
                temp="LocationService bound";

                locationService = ((LocationService.LocalBinder) service).getService();
                locationService.setProfile(Profile);
                locationService.start();
                Log.e("COnnected","");
                mBound = true;              
            }
            public void onServiceDisconnected(ComponentName arg0) {
                mBound = false;
            }
        };

*

The error area: *

LocationService.setProfile(homeProfile); (works fine)       
LocationService.getL(); (Any statement beyond this point doesnt get executed)
Log.e("Executed","LS");                     settingsActivity.status.append(Boolean.toString(LocationService.isRunning()));

*

If I comment out the 2nd line, 3rd and 4th line gets executed, otherwise it doesnt! P.S: If I dont quit my activity, everything works. The problem only occurs if I quit my activity and restart it.

4

1 回答 1

0

您只能从TabActivity. 您需要为选项卡设置特定活动,然后Service从该活动访问方法。所以基本上你的xxxService.yyyMethod()电话应该在活动中。

于 2012-04-28T09:42:30.013 回答