zoukankan      html  css  js  c++  java
  • U3

    一个项目里面可以有多个Activity

    AndroidManifest.xml
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    在谁的里面就运行谁


    在两个Activity 里切换
    
    package com.example.chapter31;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Log.i("Activity1","onCreate");
            Button  button =(Button)findViewById(R.id.button);
            button.setOnClickListener (new View.OnClickListener(){
                @Override
                public void onClick (View view){
                    Intent intent = new Intent (MainActivity.this,SecondActivity.class);
                    startActivity(intent);
                }});
        }
        @Override
        protected void onStart() {
            super.onStart();
            Log.i("Activity1","onStart()");
        }
        @Override
        protected void onRestart() {
            super.onRestart();
            Log.i("Activity1","onRestart()");
        }
        @Override
        protected void onResume() {
            super.onResume();
            Log.i("Activity1","onResume()");
        }
        @Override
        protected void onPause() {
            super.onPause();
            Log.i("Activity1","onPause()");
        }
        @Override
        protected void onStop() {
            super.onStop();
            Log.i("Activity1","onStop()");
        }
        @Override
        protected void onDestroy() {
            super.onDestroy();
            Log.i("Activity1","onDestroy()");
        }
    }
    
    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    <Button
        android:id = "@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight = "1"
        android:text = "跳转到第二个Activity"  />
    
    
    
    </LinearLayout>
    
    
    
    package com.example.chapter31;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    
    
    public class SecondActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.layout1);
            Log.i("Activity1","onCreate");
            Button button = (Button)findViewById(R.id.button);
            button.setOnClickListener (new View.OnClickListener(){
                @Override
                public void onClick (View view){
                    Intent intent = new Intent (SecondActivity.this,MainActivity.class);
    从2到1
                    startActivity(intent);
                }});
        }
        @Override
        protected void onStart() {
            super.onStart();
            Log.i("Activity2","onStart()");
        }
        @Override
        protected void onRestart() {
            super.onRestart();
            Log.i("Activity2","onRestart()");
        }
        @Override
        protected void onResume() {
            super.onResume();
            Log.i("Activity2","onResume()");
        }
        @Override
        protected void onPause() {
            super.onPause();
            Log.i("Activity2","onPause()");
        }
        @Override
        protected void onStop() {
            super.onStop();
            Log.i("Activity2","onStop()");
        }
        @Override
        protected void onDestroy() {
            super.onDestroy();
            Log.i("Activity2","onDestroy()");
        }
    }
    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".SecondActivity">
        <Button
            android:id = "@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight = "1"
            android:text = "跳转到Activity1"  />
    
    
    
    </LinearLayout>
    
    别忘了在AndroidManifest 里面注册
  • 相关阅读:
    基于OpenVINO的端到端DL网络-GOMfcTemplate在vs2017上的运行并融合Dnn模块
    Windows环境下最新OpenCV和Contribute代码的联合编译【20190505更新红字】
    图像处理程序的序列化和反序列化
    OpenCv dnn模块扩展研究(1)--style transfer
    OpenCV自带dnn的Example研究(5)— segmentation
    OpenCV自带dnn的Example研究(6)— text_detection
    OpenCV自带dnn的Example研究(3)— object_detection
    OpenCV自带dnn的Example研究(4)— openpose
    OpenCV自带dnn的Example研究(1)— classification
    OpenCV自带dnn的Example研究(2)— colorization
  • 原文地址:https://www.cnblogs.com/tingtin/p/10798090.html
Copyright © 2011-2022 走看看