詳解Android中AsyncTask的使用方法
在Android中實(shí)現(xiàn)異步任務(wù)機(jī)制有兩種方式,Handler和AsyncTask。
Handler模式需要為每一個(gè)任務(wù)創(chuàng)建一個(gè)新的線程,任務(wù)完成后通過(guò)Handler實(shí)例向UI線程發(fā)送消息,完成界面的更新,這種方式對(duì)于整個(gè)過(guò)程的控制比較精細(xì),但也是有缺點(diǎn)的,例如代碼相對(duì)臃腫,在多個(gè)任務(wù)同時(shí)執(zhí)行時(shí),不易對(duì)線程進(jìn)行精確的控制。
為了簡(jiǎn)化操作,Android1.5提供了工具類(lèi)android.os.AsyncTask,它使創(chuàng)建異步任務(wù)變得更加簡(jiǎn)單,不再需要編寫(xiě)任務(wù)線程和Handler實(shí)例即可完成相同的任務(wù)。
先來(lái)看看AsyncTask的定義:
public abstract class AsyncTask<Params, Progress, Result> {
三種泛型類(lèi)型分別代表“啟動(dòng)任務(wù)執(zhí)行的輸入?yún)?shù)”、“后臺(tái)任務(wù)執(zhí)行的進(jìn)度”、“后臺(tái)計(jì)算結(jié)果的類(lèi)型”。在特定場(chǎng)合下,并不是所有類(lèi)型都被使用,如果沒(méi)有被使用,可以用Java.lang.Void類(lèi)型代替。
一個(gè)異步任務(wù)的執(zhí)行一般包括以下幾個(gè)步驟:
1.execute(Params... params),執(zhí)行一個(gè)異步任務(wù),需要我們?cè)诖a中調(diào)用此方法,觸發(fā)異步任務(wù)的執(zhí)行。
2.onPreExecute(),在execute(Params... params)被調(diào)用后立即執(zhí)行,一般用來(lái)在執(zhí)行后臺(tái)任務(wù)前對(duì)UI做一些標(biāo)記。
3.doInBackground(Params... params),在onPreExecute()完成后立即執(zhí)行,用于執(zhí)行較為費(fèi)時(shí)的操作,此方法將接收輸入?yún)?shù)和返回計(jì)算結(jié)果。在執(zhí)行過(guò)程中可以調(diào)用publishProgress(Progress... values)來(lái)更新進(jìn)度信息。
4.onProgressUpdate(Progress... values),在調(diào)用publishProgress(Progress... values)時(shí),此方法被執(zhí)行,直接將進(jìn)度信息更新到UI組件上。
5.onPostExecute(Result result),當(dāng)后臺(tái)操作結(jié)束時(shí),此方法將會(huì)被調(diào)用,計(jì)算結(jié)果將做為參數(shù)傳遞到此方法中,直接將結(jié)果顯示到UI組件上。
在使用的時(shí)候,有幾點(diǎn)需要格外注意:
1.異步任務(wù)的實(shí)例必須在UI線程中創(chuàng)建。
2.execute(Params... params)方法必須在UI線程中調(diào)用。
3.不要手動(dòng)調(diào)用onPreExecute(),doInBackground(Params... params),onProgressUpdate(Progress... values),onPostExecute(Result result)這幾個(gè)方法。
4.不能在doInBackground(Params... params)中更改UI組件的信息。
5.一個(gè)任務(wù)實(shí)例只能執(zhí)行一次,如果執(zhí)行第二次將會(huì)拋出異常。
接下來(lái),我們來(lái)看看如何使用AsyncTask執(zhí)行異步任務(wù)操作,我們先建立一個(gè)項(xiàng)目,結(jié)構(gòu)如下:
結(jié)構(gòu)相對(duì)簡(jiǎn)單一些,讓我們先看看MainActivity.java的代碼:
package com.scott.async;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends Activity {
private static final String TAG = "ASYNC_TASK";
private Button execute;
private Button cancel;
private ProgressBar progressBar;
private TextView textView;
private MyTask mTask;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
execute = (Button) findViewById(R.id.execute);
execute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//注意每次需new一個(gè)實(shí)例,新建的任務(wù)只能執(zhí)行一次,否則會(huì)出現(xiàn)異常
mTask = new MyTask();
mTask.execute("http://www.baidu.com");
execute.setEnabled(false);
cancel.setEnabled(true);
}
});
cancel = (Button) findViewById(R.id.cancel);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//取消一個(gè)正在執(zhí)行的任務(wù),onCancelled方法將會(huì)被調(diào)用
mTask.cancel(true);
}
});
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
textView = (TextView) findViewById(R.id.text_view);
}
private class MyTask extends AsyncTask<String, Integer, String> {
//onPreExecute方法用于在執(zhí)行后臺(tái)任務(wù)前做一些UI操作
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute() called");
textView.setText("loading...");
}
//doInBackground方法內(nèi)部執(zhí)行后臺(tái)任務(wù),不可在此方法內(nèi)修改UI
@Override
protected String doInBackground(String... params) {
Log.i(TAG, "doInBackground(Params... params) called");
try {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(params[0]);
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
long total = entity.getContentLength();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int count = 0;
int length = -1;
while ((length = is.read(buf)) != -1) {
baos.write(buf, 0, length);
count += length;
//調(diào)用publishProgress公布進(jìn)度,最后onProgressUpdate方法將被執(zhí)行
publishProgress((int) ((count / (float) total) * 100));
//為了演示進(jìn)度,休眠500毫秒
Thread.sleep(500);
}
return new String(baos.toByteArray(), "gb2312");
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
return null;
}
//onProgressUpdate方法用于更新進(jìn)度信息
@Override
protected void onProgressUpdate(Integer... progresses) {
Log.i(TAG, "onProgressUpdate(Progress... progresses) called");
progressBar.setProgress(progresses[0]);
textView.setText("loading..." + progresses[0] + "%");
}
//onPostExecute方法用于在執(zhí)行完后臺(tái)任務(wù)后更新UI,顯示結(jié)果
@Override
protected void onPostExecute(String result) {
Log.i(TAG, "onPostExecute(Result result) called");
textView.setText(result);
execute.setEnabled(true);
cancel.setEnabled(false);
}
//onCancelled方法用于在取消執(zhí)行中的任務(wù)時(shí)更改UI
@Override
protected void onCancelled() {
Log.i(TAG, "onCancelled() called");
textView.setText("cancelled");
progressBar.setProgress(0);
execute.setEnabled(true);
cancel.setEnabled(false);
}
}
}
布局文件main.xml代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/execute"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="execute"/>
<Button
android:id="@+id/cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:text="cancel"/>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:progress="0"
android:max="100"
style="?android:attr/progressBarStyleHorizontal"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</ScrollView>
</LinearLayout>
因?yàn)樾枰L問(wèn)網(wǎng)絡(luò),所以我們還需要在AndroidManifest.xml中加入訪問(wèn)網(wǎng)絡(luò)的權(quán)限:
<uses-permission android:name="android.permission.INTERNET"/>
我們來(lái)看一下運(yùn)行時(shí)的界面:




以上幾個(gè)截圖分別是初始界面、執(zhí)行異步任務(wù)時(shí)界面、執(zhí)行成功后界面、取消任務(wù)后界面。執(zhí)行成功后,整個(gè)過(guò)程日志打印如下:

如果我們?cè)趫?zhí)行任務(wù)時(shí)按下了“cancel”按鈕,日志打印如下:
可以看到onCancelled()方法將會(huì)被調(diào)用,onPostExecute(Result result)方法將不再被調(diào)用。
上面介紹了AsyncTask的基本應(yīng)用,有些朋友也許會(huì)有疑惑,AsyncTask內(nèi)部是怎么執(zhí)行的呢,它執(zhí)行的過(guò)程跟我們使用Handler又有什么區(qū)別呢?答案是:AsyncTask是對(duì)Thread+Handler良好的封裝,在android.os.AsyncTask代碼里仍然可以看到Thread和Handler的蹤跡。下面就向大家詳細(xì)介紹一下AsyncTask的執(zhí)行原理。
我們先看一下AsyncTask的大綱視圖:

我們可以看到關(guān)鍵幾個(gè)步驟的方法都在其中,doInBackground(Params... params)是一個(gè)抽象方法,我們繼承AsyncTask時(shí)必須覆寫(xiě)此方法;onPreExecute()、onProgressUpdate(Progress... values)、onPostExecute(Result result)、onCancelled()這幾個(gè)方法體都是空的,我們需要的時(shí)候可以選擇性的覆寫(xiě)它們;publishProgress(Progress... values)是final修飾的,不能覆寫(xiě),只能去調(diào)用,我們一般會(huì)在doInBackground(Params... params)中調(diào)用此方法;另外,我們可以看到有一個(gè)Status的枚舉類(lèi)和getStatus()方法,Status枚舉類(lèi)代碼段如下:
//初始狀態(tài)
private volatile Status mStatus = Status.PENDING;
public enum Status {
/**
* Indicates that the task has not been executed yet.
*/
PENDING,
/**
* Indicates that the task is running.
*/
RUNNING,
/**
* Indicates that {@link AsyncTask#onPostExecute} has finished.
*/
FINISHED,
}
/**
* Returns the current status of this task.
*
* @return The current status.
*/
public final Status getStatus() {
return mStatus;
}
可以看到,AsyncTask的初始狀態(tài)為PENDING,代表待定狀態(tài),RUNNING代表執(zhí)行狀態(tài),F(xiàn)INISHED代表結(jié)束狀態(tài),這幾種狀態(tài)在AsyncTask一次生命周期內(nèi)的很多地方被使用,非常重要。
介紹完大綱視圖相關(guān)內(nèi)容之后,接下來(lái),我們會(huì)從execute(Params... params)作為入口,重點(diǎn)分析一下AsyncTask的執(zhí)行流程,我們來(lái)看一下execute(Params... params)方法的代碼段:
public final AsyncTask<Params, Progress, Result> execute(Params... params) {
if (mStatus != Status.PENDING) {
switch (mStatus) {
case RUNNING:
//如果該任務(wù)正在被執(zhí)行則拋出異常
//值得一提的是,在調(diào)用cancel取消任務(wù)后,狀態(tài)仍未RUNNING
throw new IllegalStateException("Cannot execute task:"
+ " the task is already running.");
case FINISHED:
//如果該任務(wù)已經(jīng)執(zhí)行完成則拋出異常
throw new IllegalStateException("Cannot execute task:"
+ " the task has already been executed "
+ "(a task can be executed only once)");
}
}
//改變狀態(tài)為RUNNING
mStatus = Status.RUNNING;
//調(diào)用onPreExecute方法
onPreExecute();
mWorker.mParams = params;
sExecutor.execute(mFuture);
return this;
}
代碼中涉及到三個(gè)陌生的變量:mWorker、sExecutor、mFuture,我們也會(huì)看一下他們的廬山真面目:
關(guān)于sExecutor,它是java.util.concurrent.ThreadPoolExecutor的實(shí)例,用于管理線程的執(zhí)行。代碼如下:
private static final int CORE_POOL_SIZE = 5;
private static final int MAXIMUM_POOL_SIZE = 128;
private static final int KEEP_ALIVE = 10;
//新建一個(gè)隊(duì)列用來(lái)存放線程
private static final BlockingQueue<Runnable> sWorkQueue =
new LinkedBlockingQueue<Runnable>(10);
//新建一個(gè)線程工廠
private static final ThreadFactory sThreadFactory = new ThreadFactory() {
private final AtomicInteger mCount = new AtomicInteger(1);
//新建一個(gè)線程
public Thread newThread(Runnable r) {
return new Thread(r, "AsyncTask #" + mCount.getAndIncrement());
}
};
//新建一個(gè)線程池執(zhí)行器,用于管理線程的執(zhí)行
private static final ThreadPoolExecutor sExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE,
MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS, sWorkQueue, sThreadFactory);
mWorker實(shí)際上是AsyncTask的一個(gè)的抽象內(nèi)部類(lèi)的實(shí)現(xiàn)對(duì)象實(shí)例,它實(shí)現(xiàn)了Callable<Result>接口中的call()方法,代碼如下:
private static abstract class WorkerRunnable<Params, Result> implements Callable<Result> {
Params[] mParams;
}
而mFuture實(shí)際上是java.util.concurrent.FutureTask的實(shí)例,下面是它的FutureTask類(lèi)的相關(guān)信息:
/**
* A cancellable asynchronous computation.
* ...
*/
public class FutureTask<V> implements RunnableFuture<V> {
public interface RunnableFuture<V> extends Runnable, Future<V> {
/**
* Sets this Future to the result of its computation
* unless it has been cancelled.
*/
void run();
}
可以看到FutureTask是一個(gè)可以中途取消的用于異步計(jì)算的類(lèi)。
下面是mWorker和mFuture實(shí)例在AsyncTask中的體現(xiàn):
private final WorkerRunnable<Params, Result> mWorker;
private final FutureTask<Result> mFuture;
public AsyncTask() {
mWorker = new WorkerRunnable<Params, Result>() {
//call方法被調(diào)用后,將設(shè)置優(yōu)先級(jí)為后臺(tái)級(jí)別,然后調(diào)用AsyncTask的doInBackground方法
public Result call() throws Exception {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
return doInBackground(mParams);
}
};
//在mFuture實(shí)例中,將會(huì)調(diào)用mWorker做后臺(tái)任務(wù),完成后會(huì)調(diào)用done方法
mFuture = new FutureTask<Result>(mWorker) {
@Override
protected void done() {
Message message;
Result result = null;
try {
result = get();
} catch (InterruptedException e) {
android.util.Log.w(LOG_TAG, e);
} catch (ExecutionException e) {
throw new RuntimeException("An error occured while executing doInBackground()",
e.getCause());
} catch (CancellationException e) {
//發(fā)送取消任務(wù)的消息
message = sHandler.obtainMessage(MESSAGE_POST_CANCEL,
new AsyncTaskResult<Result>(AsyncTask.this, (Result[]) null));
message.sendToTarget();
return;
} catch (Throwable t) {
throw new RuntimeException("An error occured while executing "
+ "doInBackground()", t);
}
//發(fā)送顯示結(jié)果的消息
message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
new AsyncTaskResult<Result>(AsyncTask.this, result));
message.sendToTarget();
}
};
}
我們看到上面的代碼中,mFuture實(shí)例對(duì)象的done()方法中,如果捕捉到了CancellationException類(lèi)型的異常,則發(fā)送一條“MESSAGE_POST_CANCEL”的消息;如果順利執(zhí)行,則發(fā)送一條“MESSAGE_POST_RESULT”的消息,而消息都與一個(gè)sHandler對(duì)象關(guān)聯(lián)。這個(gè)sHandler實(shí)例實(shí)際上是AsyncTask內(nèi)部類(lèi)InternalHandler的實(shí)例,而InternalHandler正是繼承了Handler,下面我們來(lái)分析一下它的代碼:
private static final int MESSAGE_POST_RESULT = 0x1; //顯示結(jié)果
private static final int MESSAGE_POST_PROGRESS = 0x2; //更新進(jìn)度
private static final int MESSAGE_POST_CANCEL = 0x3; //取消任務(wù)
private static final InternalHandler sHandler = new InternalHandler();
private static class InternalHandler extends Handler {
@SuppressWarnings({"unchecked", "RawUseOfParameterizedType"})
@Override
public void handleMessage(Message msg) {
AsyncTaskResult result = (AsyncTaskResult) msg.obj;
switch (msg.what) {
case MESSAGE_POST_RESULT:
// There is only one result
//調(diào)用AsyncTask.finish方法
result.mTask.finish(result.mData[0]);
break;
case MESSAGE_POST_PROGRESS:
//調(diào)用AsyncTask.onProgressUpdate方法
result.mTask.onProgressUpdate(result.mData);
break;
case MESSAGE_POST_CANCEL:
//調(diào)用AsyncTask.onCancelled方法
result.mTask.onCancelled();
break;
}
}
}
我們看到,在處理消息時(shí),遇到“MESSAGE_POST_RESULT”時(shí),它會(huì)調(diào)用AsyncTask中的finish()方法,我們來(lái)看一下finish()方法的定義:
private void finish(Result result) {
if (isCancelled()) result = null;
onPostExecute(result); //調(diào)用onPostExecute顯示結(jié)果
mStatus = Status.FINISHED; //改變狀態(tài)為FINISHED
}
原來(lái)finish()方法是負(fù)責(zé)調(diào)用onPostExecute(Result result)方法顯示結(jié)果并改變?nèi)蝿?wù)狀態(tài)的啊。
另外,在mFuture對(duì)象的done()方法里,構(gòu)建一個(gè)消息時(shí),這個(gè)消息包含了一個(gè)AsyncTaskResult類(lèi)型的對(duì)象,然后在sHandler實(shí)例對(duì)象的handleMessage(Message msg)方法里,使用下面這種方式取得消息中附帶的對(duì)象:
AsyncTaskResult result = (AsyncTaskResult) msg.obj;
這個(gè)AsyncTaskResult究竟是什么呢,它又包含什么內(nèi)容呢?其實(shí)它也是AsyncTask的一個(gè)內(nèi)部類(lèi),是用來(lái)包裝執(zhí)行結(jié)果的一個(gè)類(lèi),讓我們來(lái)看一下它的代碼結(jié)構(gòu):
@SuppressWarnings({"RawUseOfParameterizedType"})
private static class AsyncTaskResult<Data> {
final AsyncTask mTask;
final Data[] mData;
AsyncTaskResult(AsyncTask task, Data... data) {
mTask = task;
mData = data;
}
}
看以看到這個(gè)AsyncTaskResult封裝了一個(gè)AsyncTask的實(shí)例和某種類(lèi)型的數(shù)據(jù)集,我們?cè)賮?lái)看一下構(gòu)建消息時(shí)的代碼:
//發(fā)送取消任務(wù)的消息
message = sHandler.obtainMessage(MESSAGE_POST_CANCEL,
new AsyncTaskResult<Result>(AsyncTask.this, (Result[]) null));
message.sendToTarget();
//發(fā)送顯示結(jié)果的消息
message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
new AsyncTaskResult<Result>(AsyncTask.this, result));
message.sendToTarget();
在處理消息時(shí)是如何使用這個(gè)對(duì)象呢,我們?cè)賮?lái)看一下:
result.mTask.finish(result.mData[0]); result.mTask.onProgressUpdate(result.mData);
概括來(lái)說(shuō),當(dāng)我們調(diào)用execute(Params... params)方法后,execute方法會(huì)調(diào)用onPreExecute()方法,然后由ThreadPoolExecutor實(shí)例sExecutor執(zhí)行一個(gè)FutureTask任務(wù),這個(gè)過(guò)程中doInBackground(Params... params)將被調(diào)用,如果被開(kāi)發(fā)者覆寫(xiě)的doInBackground(Params... params)方法中調(diào)用了publishProgress(Progress... values)方法,則通過(guò)InternalHandler實(shí)例sHandler發(fā)送一條MESSAGE_POST_PROGRESS消息,更新進(jìn)度,sHandler處理消息時(shí)onProgressUpdate(Progress... values)方法將被調(diào)用;如果遇到異常,則發(fā)送一條MESSAGE_POST_CANCEL的消息,取消任務(wù),sHandler處理消息時(shí)onCancelled()方法將被調(diào)用;如果執(zhí)行成功,則發(fā)送一條MESSAGE_POST_RESULT的消息,顯示結(jié)果,sHandler處理消息時(shí)onPostExecute(Result result)方法被調(diào)用。
經(jīng)過(guò)上面的介紹,相信朋友們都已經(jīng)認(rèn)識(shí)到AsyncTask的本質(zhì)了,它對(duì)Thread+Handler的良好封裝,減少了開(kāi)發(fā)者處理問(wèn)題的復(fù)雜度,提高了開(kāi)發(fā)效率,希望朋友們能多多體會(huì)一下。
- android教程之使用asynctask在后臺(tái)運(yùn)行耗時(shí)任務(wù)
- Android帶進(jìn)度條的文件上傳示例(使用AsyncTask異步任務(wù))
- Android中AsyncTask異步任務(wù)使用詳細(xì)實(shí)例(一)
- Android中使用AsyncTask實(shí)現(xiàn)文件下載以及進(jìn)度更新提示
- Android 中使用 AsyncTask 異步讀取網(wǎng)絡(luò)圖片
- Android中使用AsyncTask實(shí)現(xiàn)下載文件動(dòng)態(tài)更新進(jìn)度條功能
- Android使用AsyncTask下載圖片并顯示進(jìn)度條功能
- Android使用AsyncTask實(shí)現(xiàn)多線程下載的方法
- Android AsyncTask詳解及使用方法
- Android中AsyncTask的入門(mén)使用學(xué)習(xí)指南
相關(guān)文章
Android利用MPAndroidChart繪制曲線圖表的基礎(chǔ)教程
最近在項(xiàng)目中要用到曲線圖,于是在網(wǎng)上找了很多很多,有AChartengine,MPAndroidChart,helloChart等等,我還用過(guò)基于html5的jsChart來(lái)做過(guò),不過(guò)最終還是選擇了MPAndroidChart來(lái)做本文介紹了Android利用MPAndroidChart繪制曲線圖表的基礎(chǔ)教程,需要的朋友可以參考下。2018-03-03
Kotlin自定義實(shí)現(xiàn)支付密碼數(shù)字鍵盤(pán)的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Kotlin如何自定義實(shí)現(xiàn)支付密碼數(shù)字鍵盤(pán)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07
Android 使用AsyncTask實(shí)現(xiàn)斷點(diǎn)續(xù)傳
這篇文章主要介紹了Android 使用AsyncTask實(shí)現(xiàn)斷點(diǎn)續(xù)傳的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2018-05-05
Kotlin基礎(chǔ)學(xué)習(xí)之Deprecated與Suppress注解使用
這篇文章主要給大家介紹了關(guān)于Kotlin基礎(chǔ)學(xué)習(xí)之Deprecated與Suppress注解使用的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Kotlin具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Android在一個(gè)app中安裝并卸載另一個(gè)app的示例代碼
這篇文章主要介紹了Android在一個(gè)app中安裝并卸載另一個(gè)app的示例代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03
Android電池電量監(jiān)聽(tīng)的示例代碼
本篇文章主要介紹了Android電池電量監(jiān)聽(tīng)的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10
Android入門(mén)之PopupWindow用法實(shí)例解析
這篇文章主要介紹了Android入門(mén)之PopupWindow用法,對(duì)于Android初學(xué)者來(lái)說(shuō)有一定的學(xué)習(xí)借鑒價(jià)值,需要的朋友可以參考下2014-08-08
android實(shí)現(xiàn)接通和掛斷電話(huà)
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)接通和掛斷電話(huà)功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Android使用Handler實(shí)現(xiàn)View彈性滑動(dòng)
這篇文章主要介紹了Android使用Handler實(shí)現(xiàn)View彈性滑動(dòng),介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08

