mot so ung dung android co ban

13 95 0
mot so ung dung android co ban

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

mot so ung dung android co ban tài liệu, giáo án, bài giảng , luận văn, luận án, đồ án, bài tập lớn về tất cả các lĩnh v...

http://vietjack.com/android/index.jsp                                                                                                              Copyright  ©  vietjack.com     Best Practice Android Best Practice tập hợp kỹ thuật cách làm mà nghiên cứu, chứng minh thực tế, áp dụng làm cho sản phẩm tốt hơn, tránh nhiều vấn đề mà người khác gặp phải Best Practice bao gồm đặc điểm thiết kế có tính tương tác, hiệu suất, bảo mật, tương thích, thử nghiệm, phân phối, … Chúng thu gọn liệt kê Best Practices - User input Mỗi trường text dụng ý cho cơng việc khác Ví dụ, số trường text số trường khác number Nếu cho number tốt hết để hiển thị bàn phím số trường text cần nhập Cú pháp sau: Một điều khác trường bạn cho password, phải hiển thị mật gợi ý người dùng dễ dàng ghi nhớ mật Điều thực như: Best Practice: Tác cụ Background Có số tác vụ cụ thể ứng dụng mà chạy background Tác vụ chúng để lấy số thứ từ internet, chơi nhạc, … Nó đề nghị tác vụ chờ đợi thời gian dài không nên thực UI thread thay vào Background Service AsyncTask http://vietjack.com/                                                                                                                              Trang  chia  sẻ  các  bài  học  online  miễn  phí  Page  1   http://vietjack.com/android/index.jsp                                                                                                              Copyright  ©  vietjack.com     Service vs AsyncTask Cả hai sử dụng để thực tác vụ background, Service không bị ảnh hưởng hầu hết kiện vòng đời giao diện UI, tiếp tục chạy tình shut down AsyncTask Best Practice: Hiệu suất Hiệu suất ứng dụng nên đánh dấu Nhưng nên khác khơng front end, mà back end thiết bị kết nối với nguồn điện charging Charging từ USB từ Wire cable Khi thiết bị tự nạp, cần cập nhật thiết lập ứng dụng, chưa có, tối đa hóa refresh rate thiết bị kết nối Điều thực sau: IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = context.registerReceiver(null, ifilter); // Are we charging / charged? Full or charging int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); // How are we charging? From AC or USB int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); Best Practice: Bảo mật Riêng tư Việc bảo mật không với ứng dụng với liệu người dùng quan trọng Tính an tồn tăng cao yếu tố sau: • Sử dụng storage nội thay ngoại vi để lưu giữ cho file ứng dụng • Sử dụng Content Provider • Sử dụng SSI kết nối tới Web • Sử dụng permission thích hợp để truy cập tính khác thiết bị Ví Ví dụ sau minh họa sử dụng số Best Practice bạn nên dùng phát triển ứng dụng Android Ví dụ tạo ứng dụng cho phép bạn xác định cách sử dụng trường Text cách tăng hiệu suất việc kiểm trạng thái charging cho điện thoại Để thử nghiệm, bạn cần chạy ví dụ thiết bị thực http://vietjack.com/                                                                                                                              Trang  chia  sẻ  các  bài  học  online  miễn  phí  Page  1   http://vietjack.com/android/index.jsp                                                                                                              Copyright  ©  vietjack.com     Sau nội dung src/MainActivity.java package com.example.sairamkrishna.myapplication; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.Set; public class MainActivity extends ActionBarActivity { EditText ed1,ed2; Button b1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ed1=(EditText)findViewById(R.id.editText); ed2=(EditText)findViewById(R.id.editText2); b1=(Button)findViewById(R.id.button); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = registerReceiver(null, ifilter); int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED,-1); boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; if(usbCharge){ Toast.makeText(getApplicationContext(),"Mobile is charging on USB",Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(),"Mobile is charging on AC",Toast.LENGTH_LONG).show(); } } }); } @Override protected void onDestroy() { super.onDestroy(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } Sau nội dung activity_main.xml Sau nội dung Strings.xml My Application name="hello_world">Hello world! Settings

Ngày đăng: 02/12/2017, 07:12

Tài liệu cùng người dùng

Tài liệu liên quan