APP開啟歡迎介面後自動跳轉到主介面解決方法
阿新 • • 發佈:2019-02-02
<p>開啟APP後第一個介面為歡迎介面,完畢後自動跳轉到主介面即功能介面。</p><p>通過handler傳送訊息的方式處理。</p><p>第一步:Handler裡面定義一個訊息,即完成歡迎介面後啟動主介面</p><p>第二步:在主執行緒裡面開個新的子執行緒 執行這個訊息即可。</p>
public class WelcomeActivity extends Activity { private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { //歡迎介面完畢後啟動主介面 Intent it = new Intent(); it.setClass(WelcomeActivity.this, MainActivity.class); WelcomeActivity.this.startActivity(it); WelcomeActivity.this.finish(); } }; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcome); new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(3000); } catch (Exception e) { // TODO: handle exception } handler.sendEmptyMessage(0); } }).start(); } }