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


总结:显示跳转效率较高  不用遍历手机所有清单文件

posted on 2016-08-29 18:55  木鱼哥  阅读(133)  评论(0编辑  收藏  举报

导航