zoukankan      html  css  js  c++  java
  • 从零开始学android开发-用Intent启动Activity的方法

    启动另外一个Activity,可以有的方法有用setClass()和Component Name
    1. 先说在setClass启动一个Activity的方法吧:
    Intent intent = new Intent();
    intent.setClass(this, CreatePlaylist.class) //参数一为当前Package的context,t当前Activity的context就是this,其他Package可能用到createPackageContex()参数二为你要打开的Activity的类名
    startActivity(intent);
    2. 通过Component Name来打开的方式
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_MAIN); //添加一些特性,具体可以查看Intent文档,相关属性的介绍
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    //通过Bundle向要打开的的Activity传递一些数据
    Bundle bundle = new Bundle();
    bundle.putString("data", new String(" Hello World"));
    intent.putExtras(bundle);

    intent.setComponent(new ComponentName(
    new String("com.android.testActivity"), new String("com.android.testActivity.testActivity")));
    startActivity(intent);

  • 相关阅读:
    重构与模式:改善代码三部曲中的第三部
    将博客搬至CSDN
    管理之道(二十二)
    管理之道(二十一)
    管理之道(二十)
    管理之道(十九)
    管理之道(十八)
    管理之道(十七)
    管理之道(十六)
    管理之道(十五)
  • 原文地址:https://www.cnblogs.com/dekevin/p/4290136.html
Copyright © 2011-2022 走看看