Android版通过多种活动发送额外的数据 [英] Android send extra Data through multiple Activities

查看:110
本文介绍了Android版通过多种活动发送额外的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有意向链

1)选择文件

2)叠加了一些东西。

2) Overlay some stuff

3)在磁盘上保存

4)上传到服务器

这意味着,我使用这些命令,4次:

video_id = extras.getString("video_id");
i.putExtra("video_id", video_id);'

是否有这样做的另一种简洁的方式,而无需编写光盘或DB什么?

Is there another neat way of doing that, without having to write anything on disc or db?

推荐答案

您可以使用单独的类即的应用程序在android系统。它维护全球应用程序状态。

You can use Singleton Class i.e. Application in android. It maintains global application state.

public class GlobalClass extends Application{
    private String name;

    public String getName() {

        return name;
    }
}

分配GlobalClass.java在应用程序标签的Manifest.xml 的android:NAME =com.androidexample.globalvariable.GlobalClass

分配您可以设置或使用下列code从任何活动访问这个变量之后。

After Assigning you can set or access this variable from any activity using following code.

    final GlobalClass globalVariable = (GlobalClass) getApplicationContext();
    //Set name in global/application context
    globalVariable.setName("Android Example context variable");

   //get name frim global/application context from any other activity.
   String name = globalVariable.getName();

这篇关于Android版通过多种活动发送额外的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆