這篇文章給大家介紹android開發(fā)中怎么實(shí)現(xiàn)一個(gè)App定時(shí)跳轉(zhuǎn)功能,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
成都創(chuàng)新互聯(lián)一直在為企業(yè)提供服務(wù),多年的磨煉,使我們?cè)趧?chuàng)意設(shè)計(jì),成都全網(wǎng)營(yíng)銷推廣到技術(shù)研發(fā)擁有了開發(fā)經(jīng)驗(yàn)。我們擅長(zhǎng)傾聽企業(yè)需求,挖掘用戶對(duì)產(chǎn)品需求服務(wù)價(jià)值,為企業(yè)制作有用的創(chuàng)意設(shè)計(jì)體驗(yàn)。核心團(tuán)隊(duì)擁有超過(guò)10多年以上行業(yè)經(jīng)驗(yàn),涵蓋創(chuàng)意,策化,開發(fā)等專業(yè)領(lǐng)域,公司涉及領(lǐng)域有基礎(chǔ)互聯(lián)網(wǎng)服務(wù)雅安移動(dòng)機(jī)房、重慶App定制開發(fā)、手機(jī)移動(dòng)建站、網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)絡(luò)整合營(yíng)銷。
App的小功能點(diǎn),很簡(jiǎn)單幾十行代碼就可以實(shí)現(xiàn)
主頁(yè)面代碼
package com.buildingbuilding;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.TextView;
import com.buildingbuilding.activitys.BuildingActivity;
public class MainActivity extends AppCompatActivity {
private TextView textView;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what != 0) {
textView.setText(msg.what + "秒后進(jìn)入APP");
} else {
Intent intent = new Intent(MainActivity.this, BuildingActivity.class);
startActivity(intent);
finish();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
//全屏顯示
getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
textView = (TextView) findViewById(R.id.textView);
textView.setText("布丁布丁");
new CountDown().start();
}
//進(jìn)入APP倒計(jì)時(shí)
class CountDown extends Thread {
int count = 3;
@Override
public void run() {
try {
while (count >= 0) {
sleep(1000);
Message message = new Message();
message.what = count;
handler.sendMessage(message);
count--;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}基本思路就是,通過(guò)一個(gè)計(jì)時(shí)線程來(lái)控制主線程(即UI線程)來(lái)更新UI
通過(guò)Handler來(lái)接受來(lái)自計(jì)時(shí)線程的Message
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what != 0) {
textView.setText(msg.what + "秒后進(jìn)入APP");
} else {
Intent intent = new Intent(MainActivity.this, BuildingActivity.class);
startActivity(intent);
finish();
}
}
};2.計(jì)時(shí)線程(內(nèi)部類),設(shè)置每隔1秒睡一次,共3秒
//進(jìn)入APP倒計(jì)時(shí)
class CountDown extends Thread {
int count = 3;
@Override
public void run() {
try {
while (count >= 0) {
sleep(1000);
Message message = new Message();
message.what = count;
handler.sendMessage(message);
count--;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}3.最后別忘了在init()方法中啟動(dòng)線程
private void init() {
//全屏顯示
getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
textView = (TextView) findViewById(R.id.textView);
textView.setText("布丁布丁");
new CountDown().start();
}OK,現(xiàn)在基本都完成了,來(lái)看效果

關(guān)于android開發(fā)中怎么實(shí)現(xiàn)一個(gè)App定時(shí)跳轉(zhuǎn)功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
文章題目:android開發(fā)中怎么實(shí)現(xiàn)一個(gè)App定時(shí)跳轉(zhuǎn)功能
文章轉(zhuǎn)載:http://www.chinadenli.net/article24/pgchje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、搜索引擎優(yōu)化、網(wǎng)站設(shè)計(jì)公司、響應(yīng)式網(wǎng)站、小程序開發(fā)、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)