WEB开发网
开发学院手机开发Android 开发 Android Server类 阅读

Android Server类

 2010-10-19 20:17:26 来源:WEB开发网   
核心提示:Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.l
Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mButton1 = (Button) findViewById(R.id.button1_id); mButton1.setOnClickListener(this); mButton2 = (Button) findViewById(R.id.button2_id); mButton2.setOnClickListener(this); } public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.button1_id: Intent i = new Intent(this, mService.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startService(i); break; case R.id.button2_id: Intent i2 = new Intent(this, mService.class); stopService(i2); break; default: break; } } }

view plaincopy to clipboardprint?

1. package my.android.AppServer;

2.

3. import android.app.Service;

4. import android.content.Intent;

5. import android.os.Handler;

6. import android.os.IBinder;

7. import android.util.Log;

8.

9. public class mService extends Service {

10.

11. private Handler objHandler = new Handler();

12. private int intCounter = 0;

13.

14. private Runnable mTasks = new Runnable() {

15. public void run() {

16. intCounter++;

17. Log.i("hippo", "counter:" + Integer.toString(intCounter));

18. objHandler.postDelayed(mTasks, 1000);

19. }

20. };

21.

22. @Override

23. public void onStart(Intent intent, int startId) {

24. objHandler.postDelayed(mTasks, 1000);

25. super.onStart(intent, startId);

26. }

27.

28. @Override

29. public void onCreate() {

30. super.onCreate();

31. }

32.

33. @Override

34. public IBinder onBind(Intent intent) {

35. // TODO Auto-generated method stub

上一页  1 2 3 4 5  下一页

Tags:Android Server

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