20.11.2016 Views

ANDROID APP

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

68 บทที่ 3 เธรด เซอร์วิส รีซีฟเวอร์ และการแจ้งเตือน<br />

ชุดคำสั่งที่ 3.11 AndroidManifest.xml<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

ตัวอย่างของแอคทิวิตี้ที่กำหนดเลย์เอาต์เพื่อสั่งให้เซอร์วิสเริ่มหรือหยุดการทำงาน จะแสดงอยู่<br />

ในชุดคำสั่งที่ 3.12 และไฟล์เลย์เอาต์ที่เกี่ยวข้องกับตัวอย่างนี้จะแสดงอยู่ในชุดคำสั่งที่ 3.13<br />

ชุดคำสั่งที่ 3.12 src/com/cookbook/simple_service/SimpleActivity.java<br />

package com.cookbook.simple_service;<br />

import android.app.Activity;<br />

import android.content.Intent;<br />

import android.os.Bundle;<br />

import android.view.View;<br />

import android.widget.Button;<br />

public class SimpleActivity extends Activity {<br />

@Override<br />

protected void onCreate(Bundle savedInstanceState) {<br />

super.onCreate(savedInstanceState);<br />

setContentView(R.layout.main);<br />

Button startButton = (Button) findViewById(R.id.Button01);<br />

startButton.setOnClickListener(new View.OnClickListener() {<br />

public void onClick(View view){<br />

startService(new Intent(SimpleActivity.this,<br />

SimpleService.class));<br />

}<br />

});<br />

Button stopButton = (Button)findViewById(R.id.Button02);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!