gpt4 book ai didi

java - 无法同时将两个字符串从一个 Activity 传递到另一 Activity

转载 作者:行者123 更新时间:2023-12-01 22:22:51 26 4
gpt4 key购买 nike

我有两项 Activity “选择”和“上传”。我将两个字符串 id 和 scan_id 从一个 Activity 传递到另一个 Activity 。当我单独传递 id 时,值会正确传递。但是,当我尝试传递这两个值时,一个值会覆盖另一个值。有没有单独的方法来传递两个字符串???

SelectActivity.java

public class SelectActivity extends Activity {
String v1;
public static String EXTRA_MESSAGE_ID;
public static String EXTRA_MESSAGE_SCAN;
int flag;
String strflag;

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll()
.build();


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select);

Bundle b = getIntent().getExtras();
EditText ed=(EditText)findViewById(R.id.patient_id);
ed.setText(b.getCharSequence("Contents"));

Button button = (Button) findViewById(R.id.button1);
StrictMode.setThreadPolicy(policy);

Button CTbutton = (Button) findViewById(R.id.CTScan);
CTbutton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
flag=1;
strflag = String.valueOf(flag);
Log.e("log_tag", "sel id"+flag);
Log.e("log_tag", "sel scan"+v1);

Intent intent = new Intent(SelectActivity.this,MainActivity.class);
intent.putExtra(EXTRA_MESSAGE_ID,v1);
intent.putExtra(EXTRA_MESSAGE_SCAN,strflag);
startActivity(intent);
}
});
}
}

MainActivity.java

public class MainActivity extends Activity {    
private static final String TAG = MainActivity.class.getSimpleName();

private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100;

public static final int MEDIA_TYPE_IMAGE = 1;

private Uri fileUri;
private Button btnCapturePicture;
public static String EXTRA_MESSAGE_ID;
public static String EXTRA_MESSAGE_SCAN;
String message_id;
String message_scan;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(getResources().getString(R.color.action_bar))));
Intent intent = getIntent();
message_id = intent.getStringExtra(SelectActivity.EXTRA_MESSAGE_ID);
message_scan = intent.getStringExtra(SelectActivity.EXTRA_MESSAGE_SCAN);

Log.e("log_tag", "id"+message_id);
Log.e("log_tag", "scan"+message_scan);

btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture);
/**
* Capture image button click event
*/
btnCapturePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
captureImage();
}
});
}
}

logcat 看起来像这样:

04-01 10:57:43.671: E/log_tag(12649): connection success 
04-01 10:57:50.374: E/log_tag(12649): sel id1
04-01 10:57:50.374: E/log_tag(12649): sel scan2
04-01 10:57:50.403: E/log_tag(12649): id1
04-01 10:57:50.403: E/log_tag(12649): scan1

最佳答案

使用相同的值初始化两个 Activity 中的字符串

public static String EXTRA_MESSAGE_ID="something1";

public static String EXTRA_MESSAGE_SCAN="something2";

关于java - 无法同时将两个字符串从一个 Activity 传递到另一 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29383678/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com