zoukankan      html  css  js  c++  java
  • 06 Activity显示跳转

    <span style="font-size:18px;">package com.fmy.day8_29task;
    
    import com.fmy.day8_29task.util.MyTaskUtil;
    
    import android.app.Activity;
    import android.content.ComponentName;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
        @Override
        protected void onResume() {
            // TODO Auto-generated method stub
            super.onResume();
            MyTaskUtil.printStack(getApplicationContext());
        }
        
        public void second(View v) {
            startActivity(new Intent(this,Second.class));
        }
        public void first(View v) {
            //显示跳转制定类名无须遍历整个全部手机清单文件 效率高
            /**
             * 方式一
             * 显式跳转  new Intent(this,Second.class);
             * 实际调用componentName(this,Second.class)
             * 效率高
             */
            //Intent intent = new Intent(this,Second.class);
            //startActivity(intent);
            
            /**
             * 方式二
             * 显式跳转  intent.setClass(this, Second.class);
             * 实际调用componentName(this,Second.class)
             * 效率高
             */
            //Intent intent = new Intent();
            //intent.setClass(this, Second.class);
            //startActivity(intent);
            /**
             * 方式三
             * 显式跳转  
             * 效率高
             */
            Intent intent = new Intent();
            ComponentName componentName = new ComponentName(this, Second.class);
            intent.setComponent(componentName);
            startActivity(intent);
            /**
           /**
             * 方式四
             * 显式跳转 跳转另一个程序的 界面   
             * 效率高
             * 第一个参数 程序包名  第二个参数 某个Activity所在的包名.类名
             */
            Intent intent = new Intent();
            intent.setClassName("com.fmy.day8_29task", "com.fmy.day8_29task.Second");
            //如果类在的包为com.fmy.day8_29task 可以写成
            //intent.setClassName("com.fmy.day8_29task", ".Second");
            startActivity(intent);
        }
        
    }</span>
    

    技巧:查看某个其他程序的一个界面地址,打开某个程序的界面。查看logcat


    总结:显示跳转效率较高  不用遍历手机所有清单文件
  • 相关阅读:
    tomcat文件夹没有部署项目和Tomcat中webapps中没有运行项目-上传下载文件和图片
    eclipse和myeclipse设置默认编码格式为UTF-8
    mybatis基础学习1---(配置文件和sql语句)
    idea 快捷键以及包含字符串文件搜索
    idea 设置项目编码
    idea 取消代码下波浪线
    idea打开可选项目
    idea打印gc日志
    idea运行scala有问题
    idea简单使用
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152288.html
Copyright © 2011-2022 走看看