Có một số thực hành mà bạn có thể làm theo trong khi phát triển áp dụng Android. Đây là những đề xuất của bản thân Android và họ tiếp chuyện cải thiện đối với thời kì.

Các phương pháp hay nhất này bao gồm các tính năng thiết kế tương tác, hiệu suất, bảo mật và quyền tây riêng, khả năng xứng, thử nghiệm, phân phối và mẹo kiếm tiền. Chúng được thu hẹp lại và được kê dưới đây

thực tại tốt nhất - Nhập của người dùng

Mỗi trường văn bản được dành cho một công việc khác. Ví dụ: một số trường văn bản dành cho văn bản và một số dành cho số. Nếu nó dành cho các con số thì tốt hơn là hiển thị bàn phím số khi trường văn bản đó được tập trung. Cú pháp của nó là

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="User Name"
android:layout_below="@+id/imageView"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView"
android:numeric="integer" />
Khác sau đó nếu lĩnh vực của bạn là cho mật khẩu, sau đó nó phải hiển thị một gợi ý mật khẩu, để người dùng có thể dễ dàng nhớ mật khẩu. Nó có thể đạt được như.

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:hint="Pass Word"
android:layout_below="@+id/editText"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:password="true" />

thực tại tốt nhất - Công việc nền

Có một số công việc khăng khăng trong một vận dụng đang chạy trong nền ứng dụng. Công việc của họ có thể là lấy một số thứ từ internet, chơi nhạc e.t.c. Chúng tôi khuyên bạn không nên thực hiện các tác vụ chờ lâu dài trong chuỗi giao diện người dùng và thay vì ở chế độ nền theo dịch vụ hoặc AsyncTask.

Dịch vụ AsyncTask Vs.

Cả hai đều được dùng để thực hành các tác vụ nền, nhưng dịch vụ không bị ảnh hưởng bởi hầu hết các sự kiện trong vòng đời của giao diện người dùng, do đó nó đấu chạy trong các trường hợp sẽ tắt AsyncTask.

thực tế tốt nhất - Hiệu suất

Hiệu suất áp dụng của bạn phải được cập nhật. Nhưng nó sẽ thực hành khác nhau không phải trên giao diện người dùng, nhưng ở mặt sau khi thiết bị được kết nối với nguồn điện hoặc sạc. Sạc có thể từ USB và từ dây cáp.

Khi thiết bị của bạn đang tự sạc, bạn nên cập nhật cài đặt ứng dụng của mình nếu có, chẳng hạn như tối đa hóa tốc độ làm mới của bạn bất cứ khi nào thiết bị được kết nối. Nó có thể được thực hiện như thế này.

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_STA TUS, -1);

// How are we charging? From AC or USB.
int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLU GGED, -1);


thực tại tốt nhất - Bảo mật và quyền riêng tư

Điều rất quan trọng là áp dụng của bạn phải được bảo mật và không chỉ ứng dụng, mà còn dữ liệu người dùng và dữ liệu ứng dụng cũng phải được bảo mật. Bảo mật có thể được tăng lên bởi các yếu tố sau.

Sử dụng bộ nhớ trong thay vì bên ngoài để lưu trữ tệp ứng dụng

dùng nhà cung cấp nội dung bất cứ khi nào có

dùng SSl khi kết nối với web

dùng các quyền thích hợp để truy cập các chức năng khác nhau của thiết bị

Thí dụ

tỉ dụ dưới đây minh họa một số phương pháp hay nhất bạn nên làm theo khi phát triển áp dụng Android. Nó thùng một vận dụng cơ bản cho phép bạn chỉ định cách dùng các trường văn bản và cách tăng hiệu suất bằng cách rà soát thể sạc của điện thoại.

Để thí nghiệm với tỉ dụ này, bạn cần chạy trên một thiết bị thực tiễn.

Steps
Description

You will use Android studio IDE to create an Android application under a package com.example.sairamkrishna.myapplication.

Modify src/MainActivity.java file to add the code

Modify layout XML file res/layout/activity_main.xml add any GUI component if required.

Run the application and choose a running android device and install the application on it and verify the results.

Đây là nội dung của src / MainActivity.jav

package com.example.sairamkrishna.myapplication;

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.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

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)
status == BatteryManager.BATTERY_STATUS_FULL;

int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLU GGED,-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();


Here is the content of activity_main.xml


xml version="1.0" encoding="utf-8"?>

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

android:text="Bluetooth Example"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/abc"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="User Name"
android:layout_below="@+id/imageView"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView"
android:numeric="integer" />


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:hint="Pass Word"
android:layout_below="@+id/editText"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:password="true" />


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check"
android:id="@+id/button"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true" />


Here is the content of Strings.xml

name="app_name">My Application

Here is the content of AndroidManifest.xml

xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication" >


android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >


android:name="com.example.sairamkrishna.myapplicat ion.MainActivity"
android:label="@string/app_name" >


android:name="android.intent.action.MAIN" />
android:name="android.intent.category.LAUNCHER" />

Hãy thử chạy áp dụng của bạn. Tôi cho rằng bạn đã kết nối thiết bị Android Mobile thực tại với máy tính của mình. Để chạy vận dụng từ Android studio, hãy mở một trong các tệp hoạt động của dự án của bạn và nhấp vào Chạy biểu trưng tượng trưng Chạy Eclipse từ thanh dụng cụ. Android Studio sẽ hiển thị Hình ảnh sau.

Ảnh trên cho thấy đầu ra của áp dụng

hiện thời chỉ cần gõ vào lĩnh vực tên người dùng và bạn sẽ thấy được xây dựng trong các đề xuất android từ từ điển sẽ bắt đầu sắp tới. Điều này được hiển thị ở trên.

hiện thời bạn sẽ thấy trường mật khẩu. Nó sẽ biến mất ngay sau khi bạn bắt đầu viết trong lĩnh vực này. Nó được hiển thị ở trên.

chung cục, chỉ cần kết nối thiết bị của bạn với cáp AC hoặc cáp USB và nhấn vào nút kiểm tra sạc. Trong trường hợp của tôi, tôi kết nối nguồn AC, nó hiển thị thông tin sau.