android實(shí)現(xiàn)App活動定時(shí)自動跳轉(zhuǎn)效果
App的小功能點(diǎn),很簡單幾十行代碼就可以實(shí)現(xiàn)
主頁面代碼
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(); } } } }
基本思路就是,通過一個(gè)計(jì)時(shí)線程來控制主線程(即UI線程)來更新UI
通過Handler來接受來自計(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()方法中啟動線程
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)在基本都完成了,來看效果
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- android 引導(dǎo)界面的實(shí)現(xiàn)方法
- Android使用ViewPager實(shí)現(xiàn)啟動引導(dǎo)頁
- Android開發(fā)實(shí)戰(zhàn)之漂亮的ViewPager引導(dǎo)頁
- 很贊的引導(dǎo)界面效果Android控件ImageSwitcher實(shí)現(xiàn)
- Android 新手引導(dǎo)蒙層效果實(shí)現(xiàn)代碼示例
- Android繪制炫酷引導(dǎo)界面
- Android引導(dǎo)頁面的簡單實(shí)現(xiàn)
- Android應(yīng)用自動跳轉(zhuǎn)到應(yīng)用市場詳情頁面的方法
- ViewPager實(shí)現(xiàn)帶引導(dǎo)小圓點(diǎn)與自動跳轉(zhuǎn)的引導(dǎo)界面
相關(guān)文章
Android自定義View實(shí)現(xiàn)角度選擇器
前幾天在Google Photos查看照片,用了一下它的圖片剪裁功能,于是我馬上就被其界面和操作吸引。后來想模仿做一個(gè)和Google Photos裁圖頁面幾乎一模一樣的角度選擇器,本文比較基礎(chǔ),在閱讀本文前只需要掌握最基礎(chǔ)的自定義View知識和Android事件知識。下面來一起學(xué)習(xí)下吧。2016-11-11使用Android Studio 開發(fā)自己的SDK教程
很多時(shí)候我們要將自己開發(fā)一個(gè)類庫打包成jar包以供他調(diào)用,這個(gè)jar包也叫你自己的SDK或者叫l(wèi)ibrary。android studio生成jar包的方法與eclipse有所不同。在studio中l(wèi)ibrary其實(shí)是module的概念。2017-10-10Android加載對話框同時(shí)異步執(zhí)行實(shí)現(xiàn)方法
Android中通過子線程連接網(wǎng)絡(luò)獲取資料,同時(shí)顯示加載進(jìn)度對話框給用戶的操作2012-11-11Android應(yīng)用借助LinearLayout實(shí)現(xiàn)垂直水平居中布局
這篇文章主要介紹了Android應(yīng)用借助LinearLayout實(shí)現(xiàn)垂直水平居中布局的方法,文中列舉了LinearLayout線性布局下居中相關(guān)的幾個(gè)重要參數(shù),需要的朋友可以參考下2016-04-04手勢滑動結(jié)束Activity基本功能的實(shí)現(xiàn)(一)
這篇文章主要為大家詳細(xì)介紹了手勢滑動結(jié)束Activity基本功能的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06Android Drawable及其相關(guān)類的使用
本文主要講解Android Drawable,這里整理了Drawable 的文檔資料和實(shí)例代碼以及實(shí)現(xiàn)效果圖,有需要的小伙伴可以參考下2016-08-08android實(shí)現(xiàn)一鍵鎖屏和一鍵卸載的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于android如何實(shí)現(xiàn)一鍵鎖屏和一鍵卸載的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-05-05Android中AnimationDrawable使用的簡單實(shí)例
這篇文章介紹了Android中AnimationDrawable使用的簡單實(shí)例,有需要的朋友可以參考一下2013-10-10