zoukankan      html  css  js  c++  java
  • onNewIntent 作用

    
    

    按 home 键,再打开app,会调用onNewIntent()

    按 back 键,再打开app,会调用onCreate()

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Log.i("MainActivity", "---------------------------onCreate ");   
        }
    
    
        
        @Override    
        protected void onNewIntent(Intent intent) {    
            
            Log.i("MainActivity", "---------------------------onNewIntent  intent = "+intent);   
            setIntent(intent);
            super.onNewIntent(intent);   
        }
    
    }
     <activity
             android:name="com.example.badupush.MainActivity"
             android:label="@string/app_name" 
             android:launchMode="singleTask">
             <intent-filter>
                  <action android:name="android.intent.action.MAIN" />
                  <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
     </activity>

    onCreate是用来创建一个activity的,但activity处于任务栈的顶端时,再次打开该Activity不会调用onCreate。

    如果你想用这个顶端的activity去处理新的Intent,可以利用onNewIntent()

  • 相关阅读:
    About cookie
    关于在Servlet中的Fileter
    看完这篇正则表达式,50岁的马化腾眼睛湿润了
    Tutorial中的hello2代码
    Development descriptor
    What is the Annotation?
    剖析容器的注入技术
    LDAP & Implentation
    RESTful levels、HATEOAS
    Mysql8.0导入数据时出错
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3512881.html
Copyright © 2011-2022 走看看