Android Service 笔记
2010-08-22 04:47:00 来源:WEB开发网}
private ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mService = ((MyTestService.LocalBinder)(service)).getService();
Log.i(TAG, "in onServiceConnected");
}
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
Log.i(TAG, "in onServiceDisconnected");
}
};
private void startService() {
Intent i = new Intent(this, MyTestService.class);
startService(i);
}
private void stopService() {
Intent i = new Intent(this, MyTestService.class);
stopService(i);
}
private void bindService() {
Intent i = new Intent(this, MyTestService.class);
bindService(i, mServiceConnection, Context.BIND_AUTO_CREATE);
isBinded = true;
}
private void unbindService() {
if(isBinded) {
unbindService(mServiceConnection);
isBinded = false;
}
}
}
< ?xml version="1.0" encoding="utf-8"?>
< TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
< TableRow android:layout_width="fill_parent" android:gravity="center"
android:layout_height="wrap_content">
< TextView android:id="@+id/text" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:minLines="2" />
< /TableRow>
< TableRow android:layout_width="fill_parent" android:gravity="center"
android:layout_height="wrap_content" android:paddingTop="24px">
更多精彩
赞助商链接