我有一个场景,在通过登录页面登录后button,每个页面都会有一个注销activity。
点击时sign-out,我将传递session id已登录用户的,以注销。谁能指导我如何保持session id与所有人的联系activities?
这种情况的任何替代方法
我有一个场景,在通过登录页面登录后button,每个页面都会有一个注销activity。
点击时sign-out,我将传递session id已登录用户的,以注销。谁能指导我如何保持session id与所有人的联系activities?
这种情况的任何替代方法
Answers:
最简单的方法是将会话ID传递给Intent您用来启动活动的注销活动:
Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);
startActivity(intent);访问下一个活动的意图:
String sessionId = getIntent().getStringExtra("EXTRA_SESSION_ID");该文档的意图有更多的信息(看标题为“其他”一节)。
Long session_ids=getIntent().getExtras().getLong("EXTRA_SESSION_IDS");
                    setData?这两种方法有什么区别?哪一个更好?
                    在您当前的活动中,创建一个新的Intent:
String value="Hello world";
Intent i = new Intent(CurrentActivity.this, NewActivity.class);    
i.putExtra("key",value);
startActivity(i);然后在新的活动中,检索以下值:
Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("key");
    //The key argument here must match that used in the other activity
}使用此技术将变量从一个活动传递到另一个活动。
extras.getInt("new_variable_name")。如果您尝试通过getString()android 获取它,则看到给出了一个int并返回null!
                    startActivity(i);?我的意思是,我可以使活动A调用活动B,并将数据返回给活动A吗?我感到困惑吗?
                    正如Erich指出的那样,传递Intent Extras是一个好方法。
该应用对象是另一种方式,虽然,跨多个活动相同的状态打交道时(而不是让获得/把它无处不在),有时更容易,或者比的对象原语和字符串更加复杂。
您可以扩展Application,然后在其中设置/获取所需内容,并使用getApplication()从任何Activity(在同一应用程序中)访问它。
还请记住,您可能会看到的其他方法(例如静态方法)可能会出现问题,因为它们可能导致内存泄漏。应用程序也可以帮助解决此问题。
源类:
Intent myIntent = new Intent(this, NewActivity.class);
myIntent.putExtra("firstName", "Your First Name Here");
myIntent.putExtra("lastName", "Your Last Name Here");
startActivity(myIntent)目标类(NewActivity类):
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view);
    Intent intent = getIntent();
    String fName = intent.getStringExtra("firstName");
    String lName = intent.getStringExtra("lastName");
}您只需要在发送意向时发送额外内容。
像这样:
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
intent.putExtra("Variable name", "Value you want to pass");
startActivity(intent);现在,在OnCreate您的方法上,您SecondActivity可以像这样获取其他功能。
如果您发送的值是long:
long value = getIntent().getLongExtra("Variable name which you sent as an extra", defaultValue(you can give it anything));如果您发送的值是String:
String value = getIntent().getStringExtra("Variable name which you sent as an extra");如果您发送的值是Boolean:
Boolean value = getIntent().getBooleanExtra("Variable name which you sent as an extra", defaultValue);它帮助我从上下文中看到事物。这是两个例子。
startActivity。MainActivity.java
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    // "Go to Second Activity" button click
    public void onButtonClick(View view) {
        // get the text to pass
        EditText editText = (EditText) findViewById(R.id.editText);
        String textToPass = editText.getText().toString();
        // start the SecondActivity
        Intent intent = new Intent(this, SecondActivity.class);
        intent.putExtra(Intent.EXTRA_TEXT, textToPass);
        startActivity(intent);
    }
}getIntent()用来Intent启动第二个活动。然后,您可以使用getExtras()在第一个活动中定义的和键提取数据。由于我们的数据是字符串,因此我们将在getStringExtra这里使用。SecondActivity.java
public class SecondActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        // get the text from MainActivity
        Intent intent = getIntent();
        String text = intent.getStringExtra(Intent.EXTRA_TEXT);
        // use the text in a TextView
        TextView textView = (TextView) findViewById(R.id.textView);
        textView.setText(text);
    }
}startActivityForResult,为其提供任意结果代码。onActivityResult。当第二个活动完成时,将调用此方法。您可以通过检查结果代码来确保它实际上是第二个活动。(当您从同一个主要活动开始多个不同的活动时,这很有用。)Intent。使用键值对提取数据。我可以使用任何字符串作为键,但是Intent.EXTRA_TEXT由于要发送文本,因此将使用预定义的字符串。MainActivity.java
public class MainActivity extends AppCompatActivity {
    private static final int SECOND_ACTIVITY_REQUEST_CODE = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    // "Go to Second Activity" button click
    public void onButtonClick(View view) {
        // Start the SecondActivity
        Intent intent = new Intent(this, SecondActivity.class);
        startActivityForResult(intent, SECOND_ACTIVITY_REQUEST_CODE);
    }
    // This method is called when the second activity finishes
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // check that it is the SecondActivity with an OK result
        if (requestCode == SECOND_ACTIVITY_REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                // get String data from Intent
                String returnString = data.getStringExtra(Intent.EXTRA_TEXT);
                // set text view with string
                TextView textView = (TextView) findViewById(R.id.textView);
                textView.setText(returnString);
            }
        }
    }
}Intent。数据Intent使用键值对存储。我选择使用Intent.EXTRA_TEXT我的钥匙。RESULT_OK并添加保存数据的意图。finish()以关闭第二个活动。SecondActivity.java
public class SecondActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
    }
    // "Send text back" button click
    public void onButtonClick(View view) {
        // get the text from the EditText
        EditText editText = (EditText) findViewById(R.id.editText);
        String stringToPassBack = editText.getText().toString();
        // put the String to pass back into an Intent and close this activity
        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_TEXT, stringToPassBack);
        setResult(RESULT_OK, intent);
        finish();
    }
}更新的注释,我已经提到了SharedPreference的使用。它具有简单的API,可在应用程序的所有活动中进行访问。但这是一个笨拙的解决方案,如果您传递敏感数据,则会带来安全风险。最好使用意图。它具有大量的重载方法,可用于更好地在活动之间传输许多不同的数据类型。看看intent.putExtra。该链接很好地展示了putExtra的用法。
在活动之间传递数据时,我的首选方法是为相关活动创建一个静态方法,其中包括启动意图所需的参数。然后可以轻松地设置和检索参数。所以看起来像这样
public class MyActivity extends Activity {
    public static final String ARG_PARAM1 = "arg_param1";
...
public static getIntent(Activity from, String param1, Long param2...) {
    Intent intent = new Intent(from, MyActivity.class);
        intent.putExtra(ARG_PARAM1, param1);
        intent.putExtra(ARG_PARAM2, param2);
        return intent;
}
....
// Use it like this.
startActivity(MyActvitiy.getIntent(FromActivity.this, varA, varB, ...));
...然后,您可以为预期的活动创建一个意图,并确保您拥有所有参数。您可以适应片段。上面有一个简单的例子,但是您知道了。
尝试执行以下操作:
创建一个简单的“ helper”类(您的Intent的工厂),如下所示:
import android.content.Intent;
public class IntentHelper {
    public static final Intent createYourSpecialIntent(Intent src) {
          return new Intent("YourSpecialIntent").addCategory("YourSpecialCategory").putExtras(src);
    }
}这将是您所有Intent的工厂。每当您需要新的Intent时,都可以在IntentHelper中创建一个静态工厂方法。要创建一个新的Intent,您应该这样说:
IntentHelper.createYourSpecialIntent(getIntent());在您的活动中。当您要“保存”“会话”中的某些数据时,只需使用以下命令:
IntentHelper.createYourSpecialIntent(getIntent()).putExtra("YOUR_FIELD_NAME", fieldValueToSave);并发送此意图。在目标活动中,您的字段将显示为:
getIntent().getStringExtra("YOUR_FIELD_NAME");因此,现在我们可以像以前的旧会话一样使用Intent(例如在servlet或JSP中)。
您还可以通过创建可拆分的类来传递自定义类对象。使其可拆分的最佳方法是编写您的类,然后将其简单地粘贴到http://www.parcelabler.com/之类的网站上。单击构建,您将获得新代码。复制所有这些内容并替换原始的类内容。然后-
Intent intent = new Intent(getBaseContext(), NextActivity.class);
Foo foo = new Foo();
intent.putExtra("foo", foo);
startActivity(intent);并在NextActivity中获得结果,例如-
Foo foo = getIntent().getExtras().getParcelable("foo");现在,您可以像使用过的那样简单地使用foo对象。
另一种方法是使用存储数据的公共静态字段,即:
public class MyActivity extends Activity {
  public static String SharedString;
  public static SomeObject SharedObject;
//...在活动之间传递数据的最方便方法是传递意图。在您要发送数据的第一个活动中,应添加代码,
String str = "My Data"; //Data you want to send
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("name",str); //Here you will add the data into intent to pass bw activites
v.getContext().startActivity(intent);您还应该导入
import android.content.Intent;然后,在下一个Acitvity(SecondActivity)中,应该使用以下代码从意图中检索数据。
String name = this.getIntent().getStringExtra("name");您可以使用SharedPreferences...
正在记录。中的时间存储会话IDSharedPreferences
SharedPreferences preferences = getSharedPreferences("session",getApplicationContext().MODE_PRIVATE);
Editor editor = preferences.edit();
editor.putString("sessionId", sessionId);
editor.commit();登出。共享首选项中的时间获取会话ID
SharedPreferences preferences = getSharedPreferences("session", getApplicationContext().MODE_PRIVATE);
String sessionId = preferences.getString("sessionId", null);如果您没有必需的会话ID,请删除sharedpreferences:
SharedPreferences settings = context.getSharedPreferences("session", Context.MODE_PRIVATE);
settings.edit().clear().commit();这非常有用,因为有一次您保存了值,然后在任何地方检索活动。
标准方法。
Intent i = new Intent(this, ActivityTwo.class);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
String getrec=textView.getText().toString();
Bundle bundle = new Bundle();
bundle.putString(“stuff”, getrec);
i.putExtras(bundle);
startActivity(i);现在在第二个活动中,从捆绑包中检索数据:
获取捆绑
Bundle bundle = getIntent().getExtras();提取数据…
String stuff = bundle.getString(“stuff”); 来自活动
 int n= 10;
 Intent in = new Intent(From_Activity.this,To_Activity.class);
 Bundle b1 = new Bundle();
 b1.putInt("integerNumber",n);
 in.putExtras(b1);
 startActivity(in);到活动
 Bundle b2 = getIntent().getExtras();
 int m = 0;
 if(b2 != null)
  {
     m = b2.getInt("integerNumber");
  }Bundle基础的方法已经提出PRABEESH RK在2012年和阿贾伊Venugopal,克里希纳。并可以减少到i.putExtras()/ getIntent().getString()由其他8个答案提出
                    您可以使用意图对象在活动之间发送数据。考虑您有两项活动,即FirstActivity和SecondActivity。
在FirstActivity内部:
使用意图:
i = new Intent(FirstActivity.this,SecondActivity.class);
i.putExtra("key", value);
startActivity(i)内部SecondActivity
Bundle bundle= getIntent().getExtras();现在,您可以使用不同的捆绑软件类方法来获取通过Key从FirstActivity传递的值。
例如
 bundle.getString("key"),bundle.getDouble("key"),bundle.getInt("key")等。
Bundle基础方法已由PRABEESH RK和Ajay Venugopal在2012年提出。并可以减少到i.putExtras()/ getIntent().getString()由其他7个答案提出的建议
                    如果要在活动/片段之间转移位图
活动
在活动之间传递位图
Intent intent = new Intent(this, Activity.class);
intent.putExtra("bitmap", bitmap);并在Activity类中
Bitmap bitmap = getIntent().getParcelableExtra("bitmap");分段
在片段之间传递位图
SecondFragment fragment = new SecondFragment();
Bundle bundle = new Bundle();
bundle.putParcelable("bitmap", bitmap);
fragment.setArguments(bundle);在SecondFragment内部接收
Bitmap bitmap = getArguments().getParcelable("bitmap");传输大位图
如果您的活页夹交易失败,这意味着您将活页夹大笔交易从一个活动转移到另一活动,从而超出了活页夹交易缓冲区。
因此,在这种情况下,您必须将位图压缩为字节数组,然后在另一个活动中将其解压缩,如下所示
在FirstActivity中
Intent intent = new Intent(this, SecondActivity.class);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPG, 100, stream);
byte[] bytes = stream.toByteArray(); 
intent.putExtra("bitmapbytes",bytes);而在SecondActivity中
byte[] bytes = getIntent().getByteArrayExtra("bitmapbytes");
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);Intent intent = new Intent(YourCurrentActivity.this, YourActivityName.class);
intent.putExtra("NAme","John");
intent.putExtra("Id",1);
startActivity(intent);您可以在另一个活动中检索它。两种方式:
int id = getIntent.getIntExtra("id", /* defaltvalue */ 2);第二种方法是:
Intent i = getIntent();
String name = i.getStringExtra("name");这是我的最佳实践,当项目庞大而复杂时,它会有所帮助。
假设我有2个活动,LoginActivity并且HomeActivity。我想从通过2个参数(用户名和密码)LoginActivity来HomeActivity。
首先,我创建我的 HomeIntent
public class HomeIntent extends Intent {
    private static final String ACTION_LOGIN = "action_login";
    private static final String ACTION_LOGOUT = "action_logout";
    private static final String ARG_USERNAME = "arg_username";
    private static final String ARG_PASSWORD = "arg_password";
    public HomeIntent(Context ctx, boolean isLogIn) {
        this(ctx);
        //set action type
        setAction(isLogIn ? ACTION_LOGIN : ACTION_LOGOUT);
    }
    public HomeIntent(Context ctx) {
        super(ctx, HomeActivity.class);
    }
    //This will be needed for receiving data
    public HomeIntent(Intent intent) {
        super(intent);
    }
    public void setData(String userName, String password) {
        putExtra(ARG_USERNAME, userName);
        putExtra(ARG_PASSWORD, password);
    }
    public String getUsername() {
        return getStringExtra(ARG_USERNAME);
    }
    public String getPassword() {
        return getStringExtra(ARG_PASSWORD);
    }
    //To separate the params is for which action, we should create action
    public boolean isActionLogIn() {
        return getAction().equals(ACTION_LOGIN);
    }
    public boolean isActionLogOut() {
        return getAction().equals(ACTION_LOGOUT);
    }
}这是我在LoginActivity中传递数据的方式
public class LoginActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        String username = "phearum";
        String password = "pwd1133";
        final boolean isActionLogin = true;
        //Passing data to HomeActivity
        final HomeIntent homeIntent = new HomeIntent(this, isActionLogin);
        homeIntent.setData(username, password);
        startActivity(homeIntent);
    }
}最后一步,这是我如何接收数据 HomeActivity
public class HomeActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        //This is how we receive the data from LoginActivity
        //Make sure you pass getIntent() to the HomeIntent constructor
        final HomeIntent homeIntent = new HomeIntent(getIntent());
        Log.d("HomeActivity", "Is action login?  " + homeIntent.isActionLogIn());
        Log.d("HomeActivity", "username: " + homeIntent.getUsername());
        Log.d("HomeActivity", "password: " + homeIntent.getPassword());
    }
}做完了!酷:)我只想分享我的经验。如果您从事的是小型项目,那么这不是大问题。但是,当您从事大型项目时,要重构或修复错误确实很痛苦。
传递数据的实际过程已经得到解答,但是大多数答案使用硬编码字符串作为Intent中的键名。通常,仅在您的应用程序中使用时才可以。但是,文档建议EXTRA_*对标准数据类型使用常量。
示例1:使用Intent.EXTRA_*键
第一次活动
Intent intent = new Intent(getActivity(), SecondActivity.class);
intent.putExtra(Intent.EXTRA_TEXT, "my text");
startActivity(intent);第二项活动:
Intent intent = getIntent();
String myText = intent.getExtras().getString(Intent.EXTRA_TEXT);示例2:定义自己的static final密钥
如果其中一个Intent.EXTRA_*字符串不适合您的需求,则可以在第一个活动开始时定义自己的字符串。
static final String EXTRA_STUFF = "com.myPackageName.EXTRA_STUFF";如果仅在自己的应用程序中使用密钥,则包括软件包名称只是一个约定。但是,如果要创建其他应用可以通过Intent调用的某种服务,就必须避免命名冲突。
第一次活动:
Intent intent = new Intent(getActivity(), SecondActivity.class);
intent.putExtra(EXTRA_STUFF, "my text");
startActivity(intent);第二项活动:
Intent intent = getIntent();
String myText = intent.getExtras().getString(FirstActivity.EXTRA_STUFF);示例3:使用字符串资源密钥
尽管文档中未提及,但此答案建议使用String资源,以避免活动之间的依赖关系。
strings.xml
 <string name="EXTRA_STUFF">com.myPackageName.MY_NAME</string>第一次活动
Intent intent = new Intent(getActivity(), SecondActivity.class);
intent.putExtra(getString(R.string.EXTRA_STUFF), "my text");
startActivity(intent);第二次活动
Intent intent = getIntent();
String myText = intent.getExtras().getString(getString(R.string.EXTRA_STUFF));您可以使用 Intent
Intent mIntent = new Intent(FirstActivity.this, SecondActivity.class);
mIntent.putExtra("data", data);
startActivity(mIntent);另一种方法也可以使用单例模式:
public class DataHolder {
 private static DataHolder dataHolder;
 private List<Model> dataList;
 public void setDataList(List<Model>dataList) {
    this.dataList = dataList;
 }
 public List<Model> getDataList() {
    return dataList;
 }
 public synchronized static DataHolder getInstance() {
    if (dataHolder == null) {
       dataHolder = new DataHolder();
    }
    return dataHolder;
 }
}来自您的FirstActivity
private List<Model> dataList = new ArrayList<>();
DataHolder.getInstance().setDataList(dataList);论SecondActivity
private List<Model> dataList = DataHolder.getInstance().getDataList();活动之间的数据传递主要是通过意图对象进行的。
首先,您必须使用Bundle该类将数据附加到意图对象。然后使用startActivity()或startActivityForResult()方法调用活动。
您可以通过博客文章“将数据传递给Activity”中的示例找到有关它的更多信息。
您可以尝试使用共享首选项,这可能是在活动之间共享数据的一个不错的选择
要保存会话ID-
SharedPreferences pref = myContexy.getSharedPreferences("Session 
Data",MODE_PRIVATE);
SharedPreferences.Editor edit = pref.edit();
edit.putInt("Session ID", session_id);
edit.commit();为了让他们-
SharedPreferences pref = myContexy.getSharedPreferences("Session Data", MODE_PRIVATE);
session_id = pref.getInt("Session ID", 0);通过Bundle Object从此活动传递参数开始另一个活动
Intent intent = new Intent(getBaseContext(), YourActivity.class);
intent.putExtra("USER_NAME", "xyz@gmail.com");
startActivity(intent);检索另一个活动(YourActivity)
String s = getIntent().getStringExtra("USER_NAME");对于简单种类的数据类型来说可以。但是,如果您想在两次活动之间传递复杂的数据,则需要先对其进行序列化。
这里有员工模型
class Employee{
    private String empId;
    private int age;
    print Double salary;
    getters...
    setters...
}您可以使用Google提供的Gson lib来序列化复杂数据,如下所示
String strEmp = new Gson().toJson(emp);
Intent intent = new Intent(getBaseContext(), YourActivity.class);
intent.putExtra("EMP", strEmp);
startActivity(intent);
Bundle bundle = getIntent().getExtras();
String empStr = bundle.getString("EMP");
            Gson gson = new Gson();
            Type type = new TypeToken<Employee>() {
            }.getType();
            Employee selectedEmp = gson.fromJson(empStr, type);/*
 * If you are from transferring data from one class that doesn't
 * extend Activity, then you need to do something like this.
 */ 
public class abc {
    Context context;
    public abc(Context context) {
        this.context = context;
    }
    public void something() {
        context.startactivity(new Intent(context, anyone.class).putextra("key", value));
    }
}查理·柯林斯给了我一个完美的答案使用Application.class。我不知道我们可以轻易地将其子类化。这是使用自定义应用程序类的简化示例。
AndroidManifest.xml提供android:name属性以使用您自己的应用程序类。
...
<application android:name="MyApplication"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
....MyApplication.java使用它作为全局参考持有人。在同一过程中它可以正常工作。
public class MyApplication extends Application {
    private MainActivity mainActivity;
    @Override
    public void onCreate() {
        super.onCreate();
    }
    public void setMainActivity(MainActivity activity) { this.mainActivity=activity; }
    public MainActivity getMainActivity() { return mainActivity; }
}MainActivity.java将全局“单例”引用设置为应用程序实例。
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ((MyApplication)getApplication()).setMainActivity(this);
    }
    ...
}MyPreferences.java一个简单的示例,其中我使用另一个活动实例中的主要活动。
public class MyPreferences extends PreferenceActivity
            implements SharedPreferences.OnSharedPreferenceChangeListener {
    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
        PreferenceManager.getDefaultSharedPreferences(this)
            .registerOnSharedPreferenceChangeListener(this);
    }
    @Override
    public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
        if (!key.equals("autostart")) {
            ((MyApplication)getApplication()).getMainActivity().refreshUI();
        }
    }
}我最近发布了Vapor API,这是一个jQuery风格的Android框架,它使诸如此类的各种任务变得更加简单。如前所述,这SharedPreferences是您可以执行此操作的一种方法。
VaporSharedPreferences被实现为Singleton,因此这是一个选择,并且在Vapor API中,该.put(...)方法具有重载的方法,因此您不必明确担心要提交的数据类型-只要受支持即可。它也很流利,因此您可以链接呼叫:
$.prefs(...).put("val1", 123).put("val2", "Hello World!").put("something", 3.34);它还可以选择自动保存更改,并在后台统一读取和写入过程,因此您无需像在标准Android中一样显式地检索Editor。
或者,您可以使用Intent。在Vapor API中,您还可以在.put(...)上使用可链接的重载方法VaporIntent:
$.Intent().put("data", "myData").put("more", 568)...如其他答案中所述,并将其作为额外的内容传递。您可以从中检索其他内容Activity,此外,如果您使用的VaporActivity是自动完成的操作,则可以使用:
this.extras()在另一端检索它们 Activity请切换到。
希望一些人感兴趣:)
您可以通过3种方式在应用程序中的活动之间传递数据
意向传递数据有一些限制。对于大量数据,您可以使用应用程序级数据共享,并且通过将其存储在SharedPreference中,可以增加应用程序的大小
使用全局类:
public class GlobalClass extends Application
{
    private float vitamin_a;
    public float getVitaminA() {
        return vitamin_a;
    }
    public void setVitaminA(float vitamin_a) {
        this.vitamin_a = vitamin_a;
    }
}您可以从所有其他类中调用该类的设置方法和获取方法。这样做,您需要在每个Actitity中创建一个GlobalClass-Object:
GlobalClass gc = (GlobalClass) getApplication();然后您可以致电:
gc.getVitaminA()