WEB开发网
开发学院手机开发Android 开发 Android Service 笔记 阅读

Android Service 笔记

 2010-08-22 04:47:00 来源:WEB开发网   
核心提示:}private ServiceConnection mServiceConnection = new ServiceConnection() {@Overridepublic void onServiceConnected(ComponentName name, IBinder service) {mService

}

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">

上一页  1 2 3 4 5 6 7  下一页

Tags:Android Service 笔记

编辑录入:coldstar [复制链接] [打 印]
赞助商链接