Danh mục

Giáo trình hướng dẫn lập trình cơ bản với hệ điều hành mở Androi 3.1 p7

Số trang: 5      Loại file: pdf      Dung lượng: 334.67 KB      Lượt xem: 6      Lượt tải: 0    
Hoai.2512

Hỗ trợ phí lưu trữ khi tải xuống: miễn phí Tải xuống file đầy đủ (5 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

B6: Tạo BroadCast Receiver để nhận Intent mà Activity2 gửi tới - Tạo 1 file Receiver.java trong at.exam - Nội dung: Mã: package at.exam; import import import import android.content.BroadcastReceiver; android.content.Context; android.content.Intent; android.widget.Toast;
Nội dung trích xuất từ tài liệu:
Giáo trình hướng dẫn lập trình cơ bản với hệ điều hành mở Androi 3.1 p7B6: Tạo BroadCast Receiver để nhận Intent mà Activity2 gửi tới -> Tạo 1 fileReceiver.java trong at.exam -> Nội dung:Mã:package at.exam;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.widget.Toast;public class Receiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intentintent) { long value = intent.getLongExtra(newvalue, -10) + 10; Toast toast = Toast.makeText(context,Broadcast Receiver catch an Intent + + The value is stored inthe Intent is + String.valueOf(value),Toast.LENGTH_LONG); toast.show(); }}Code không hề khó hiểu, và mình cũng đã add comment. Chỉ cần lưu ý ở đây làToast là lớp để hiển thị một thông báo đơn giản trong 1 khoảng thời gian cố định,và ko thể thay đổi thời gian này T_T (why???) chỉ có thể chọn giữaLENGTH_SHORT với LENGTH_LONGB7: Bổ sung thêm thông tin về component mới vào AndroidManifest.xml:Mã:

Tài liệu được xem nhiều: