zoukankan      html  css  js  c++  java
  • AndroidStudio环境下使用Bundle在Activity之间交换数据及数据返回

    新建项目的目录树

    基础语法

    MainActivity.java(onCreate())
    Intent intent = new Intent(MainActivity.this,AnotherActivity.class);
    Bundle bundle = new Bundle();//创建并且实例化一个Bundle对象
    bundle.putCharSequence("key",value);//以键值对的形式输入数据
    intent.putExtras(bundle);//将Bundle对象添加到intent中进行传输
    startActivity(intent);//启动新的Activity
    View Code
    AnotherActivity.java(onCreate())
    Intent intent = getIntent();//获取intent对象
    Bundle bundle = intent.getExtras();//获取传递的数据包
    String value =bundle.getString("key");//通过键名来获取键值
    View Code

    注意:新增的AnotherActivity必须在AndroidManifest.xml中进行配置,否则会意外退出!!

     <activity 
        android:name=".AnotherActivity">
     </activity>
    View Code

    需要弹框时

    Toast.makeText(MainActivity.this,"xxx",Toast.LENGTH_SHORT).show();

    弹框示例:

    常用功能补充:

    AndroidStudio3.5.2更换主题方式:

    File  -->  Settings  -->  Appearance & Behavior 下的 Appearance  -->  Theme  -->  Darcula(黑色)、IntelliJ(白色)

    AndroidStudio3.5.2更换字体方式:

    File  -->  Settings  --> Editor -->  Font

    AndroidStudio3.5.2代码提示设置:

    File  -->  Settings  -->  Editor  -->  General  -->  Code Completion

     AndroidStudio3.5.自动导包设置:

    File  -->  Settings  -->  Editor  -->  General  -->  Auto Import

     代码API版本查看:

     

     安装虚拟机时需要安装相应版本,否则容易出错!

     

  • 相关阅读:
    10 个迅速提升你 Git 水平的提示
    GitLab-CI与GitLab-Runner
    WEB应用安全解决方案测试验证
    sparse representation 与sparse coding 的区别的观点
    The Ph.D. Grind
    Potential Pythonic Pitfalls
    Overfitting & Regularization
    LVM的一般操作过程
    你跟大牛之间仅仅差一个google
    Hadoop伪分布式模式部署
  • 原文地址:https://www.cnblogs.com/MuZiJin/p/12103223.html
Copyright © 2011-2022 走看看