zoukankan      html  css  js  c++  java
  • 6. Activity life cycle

    An activity can exist in essentially three states:

    Resumed
    The activity is in the foreground of the screen and has user focus. (This state is also sometimes referred to as "running".)
    Paused
    Another activity is in the foreground and has focus, but this one is still visible. That is, another activity is visible on top of this one and that activity is partially transparent or doesn't cover the entire screen. A paused activity is completely alive (the Activity object is retained in memory, it maintains all state and member information, and remains attached to the window manager), but can be killed by the system in extremely low memory situations.
    Stopped
    The activity is completely obscured by another activity (the activity is now in the "background"). A stopped activity is also still alive (the Activity object is retained in memory, it maintains all state and member information, but is not attached to the window manager). However, it is no longer visible to the user and it can be killed by the system when memory is needed elsewhere.

    If an activity is paused or stopped, the system can drop it from memory either by asking it to finish (calling itsfinish() method), or simply killing its process. When the activity is opened again (after being finished or killed), it must be created all over.

    Splash.java作用相当于一个Welcome page, 当程序开始的时候显示,显示过后就不再需要切换个主界面,但是这个welcome界面状态是purse / stop. 但是还是alive, 用户可以用回退键访问这个welcome界面。所以可以使用finish()来kill这个activity, 通常可以在onPurse()中做。

    package com.example.thenewboston;
    
    import java.util.concurrent.Executors;
    import java.util.concurrent.ScheduledExecutorService;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    
    public class Splash extends Activity{
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);
            
            ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor();
            timer.execute(new Runnable(){
    
                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }finally{
                        Intent openStartingPoint = new Intent("com.example.thenewboston.MAINACTIVITY");
                        startActivity(openStartingPoint);
                    }
                }
                
            });
        }
    
        @Override
        protected void onPause() {
            // TODO Auto-generated method stub
            super.onPause();
            //Kill this acticity
            finish();
        }
    
        
    }
  • 相关阅读:
    【洛谷3527】[POI2011] MET-Meteors(树状数组+整体二分)
    【洛谷1580】yyy loves Easter_Egg I(字符串处理题)
    【BZOJ4866】[YNOI2017] 由乃的商场之旅(莫队)
    【BZOJ4810】[YNOI2017] 由乃的玉米田(莫队+bitset)
    【洛谷1494】[国家集训队] 小Z的袜子(莫队)
    【BZOJ3668】[NOI2014] 起床困难综合症(位运算思想)
    【BZOJ3720】Gty的妹子树(主席树+时间分块)
    【BZOJ2427】[HAOI2010] 软件安装(缩点+树形DP)
    【洛谷3648】[APIO2014] 序列分割(斜率优化DP)
    动态规划专题(五)——斜率优化DP
  • 原文地址:https://www.cnblogs.com/Answer1215/p/3434771.html
Copyright © 2011-2022 走看看