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);

  • 相关阅读:
    Mahout推荐算法ItemBased
    ALSA安装编程指南
    windbg更改cmd的token提升其特权
    至尊问题
    什么是“Bash”破绽?
    hdu 1548 A strange lift
    C 循环链表
    C++ 链表
    C_数据结构_链表的链式实现
    C _数据结构 _线性表的顺序存储
  • 原文地址:https://www.cnblogs.com/dekevin/p/4290136.html
Copyright © 2011-2022 走看看