如何使用Objects从一个Activity获取String的值到其他Activity?

时间:2016-09-02 15:06:45

标签: android variables android-activity methods instance-variables

我有两个活动--ExampleActivity,Another

我想传输String“beba”的值,它被初始化为实例变量,然后在oncreate方法中修改为“AnotherActivity”中的“Another”活动,而不使用intent和sharedpreference

问题=以下代码在日志中打印值“a”(已初始化)

我想要的=在日志中打印来自oncreate方法“please”的修改值

第一项活动

package com.android.example;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;



public class ExampleActivity extends Activity {
String beba="a";

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    beba="please";

    Button b=(Button)findViewById(R.id.button1);
      b.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
        Intent n=new Intent(ExampleActivity.this,Another.class);
        startActivity(n);
        }
    });
}
public String clicked()
{
    Log.i("s",beba);
    return 
} 

这是我的第二个活动

package com.android.example;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class Another extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.another);
    ExampleActivity abc=new ExampleActivity();
    String papa=abc.clicked();
    Log.i("papa", papa);
}

}

0 个答案:

没有答案