Hướng dẫn lập trình với Android part 19

Mỗi ứng dụng đều sử dụng dữ liệu, dữ liệu có thể đơn giản hay đôi khi là cả 1 cấu trúc. Trong Android thì hệ cơ sở dữ liệu được sử dụng là SQLite Database, đây là hệ thống mã nguồn mở được sử dụng rộng rãi trong các ứng dụng ( Mozilla Firefox sử dụng SQLite để lưu trữ các dữ liệu về cấu hình, iPhone cũng sử dụng cơ sở dữ liệu là SQLite). | Hương dan lạp trinh cơ bán VƠI Android Pairii 19 Đầu tiên là tạo 1 giao diện điều khiển Service chơi nhạc bằng layout đơn giản Mã LinearLayout xmlns android http apk res andro id android orientation vertical android padding 4dip android gravity center_horizontal android layout_width fill_parent android layout_height fill_parent TextView android layout_width fill_parent android layout_height wrap_content android layout_weight 0 android paddingBottom 4dip android text @string local_service_binding Button android id @ id bind android layout_width wrap_content android layout_height wrap_content android text @string bind_service requestFocus Button Button android id @ id unbind android layout_width wrap_content android layout_height wrap_content android text @string unbind_service Button Button android id @ id play android layout_width wrap_content android layout_height wrap_content android text @string Play Button LinearLayout Tạo 1 class LocalServicejava extend từ Service và một lớp con LocalBinder thừa kế từ lớp Binder dùng để điều khiến service Mã public class LocalService extends Service public class LocalBinder extends Binder LocalService getService return Từ đó nạp chồng phương thức onBind bằng cách trả lại giá trị mBinder Mã private final IBinder mBinder new LocalBinder @Override public IBinder onBind Intent intent return mBinder Tạo một đối tượng MediaPlayer chơi nhạc đơn giản sử dụng để chơi file đặt trong folder res raw y. Mã MediaPlayer mMediaPlayer public void startMp3Player mMediaPlayer getApplicationContext public void mp3Stop Ở lớp LocalServiceBindingjava extend từ lớp Activity chúng ta chỉ cần để ý đến đối tượng mConnection có nhiệm vụ giám sát kết nối của service chơi nhạc. Mã private Serviceconnection mConnection new ServiceConnection public void onServiceConnected ComponentName className IBinder service mBoundService .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU XEM NHIỀU
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.