background image

9.

        android:layout_width=

"fill_parent"

   

10.

        android:layout_height=

"wrap_content"

   

11.

        android:text=

"@string/hello"

  

12.

        />  

13.

    <Button  

14.

        android:id=

"@+id/startservice"

  

15.

        android:layout_width=

"fill_parent"

  

16.

        android:layout_height=

"wrap_content"

  

17.

        android:text=

"startService"

  

18.

    />  

19.

    <Button  

20.

        android:id=

"@+id/stopservice"

  

21.

        android:layout_width=

"fill_parent"

  

22.

        android:layout_height=

"wrap_content"

  

23.

        android:text=

"stopService"

  

24.

    />  

25.

    <Button  

26.

        android:id=

"@+id/bindservice"

  

27.

        android:layout_width=

"fill_parent"

  

28.

        android:layout_height=

"wrap_content"

  

29.

        android:text=

"bindService"

  

30.

    />  

31.

    <Button  

32.

        android:id=

"@+id/unbindservice"

  

33.

        android:layout_width=

"fill_parent"

  

34.

        android:layout_height=

"wrap_content"

  

35.

        android:text=

"unbindService"

  

36.

    />  

37.

</LinearLayout>  

第三步

:新建一个 Service,命名为 MyService.java 代码如下:

view plain

 

 copy to clipboard

 

 print

 

 ?  

1.

package

 com.tutor.servicedemo;  

2.

import

 android.app.Service;  

3.

import

 android.content.Intent;  

4.

import

 android.os.Binder;  

5.

import

 android.os.IBinder;  

6.

import

 android.text.format.Time;  

7.

import

 android.util.Log;  

8.

public

 

class

 MyService 

extends

 Service {