gpt4 book ai didi

java - 如何为 Activity 创建 Intent 二

转载 作者:太空宇宙 更新时间:2023-11-04 14:06:58 25 4
gpt4 key购买 nike

我是 Java 新手,所以它让我有点困惑,我想为 Activity 二创建一个 Intent ,但我编写的代码似乎有问题。

               @Override
public void onClick(View v) {
// TODO:
// Launch Activity Two
// Hint: use Context's startActivity() method

// Create an intent stating which Activity you would like to
// start

Intent activityTwo = new Intent(ActivityTwo.this.finish());


Intent intent = null;

// Launch the Activity using the intent
startActivity(activityTwo);
}
});

// Has previous state been saved?
if (savedInstanceState != null) {

// TODO:
// Restore value of counters from saved state
super.onRestoreInstanceState(savedInstanceState);
mCreate = savedInstanceState.getInt(CREATE_KEY);
mRestart = savedInstanceState.getInt(RESTART_KEY);
mStart = savedInstanceState.getInt(START_KEY);




}

// Emit LogCat message
Log.i(TAG, "Entered the onCreate() method");

// TODO:

最佳答案

从第一到第二:

Button next = (Button) findViewById(R.id.button2);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),Second.class);
intent.putExtra("Tag", "Value");
startActivity(intent);
finish();
}});

第二到第一:

Button previous= (Button) findViewById(R.id.button);
previous.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),First.class);
startActivity(intent);
}});

关于java - 如何为 Activity 创建 Intent 二,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28763441/

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