22级云计算杜陈阳2022005011移动应用程序开发基础.zip
立即下载
资源介绍:
22级云计算杜陈阳2022005011移动应用程序开发基础.zip
package com.example.myapplication2;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity028 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main028);
//获取文本框中的值
//点击按钮跳转到29页面
//29页面要显示:xx登录成功
//点击29按钮,回到主页面28要显示xx已经登录成功
EditText txtname=findViewById(R.id.editTextText3);
TextView txtState=findViewById(R.id.textView6);
Button btn=findViewById(R.id.button5);
//定义一个可以结束返回值的意图对象intent(在该意图被关掉后,获取一个返回值)
ActivityResultLauncher intentActivityResultLauncher=
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode()==1) {
txtState.setText(result.getData().getStringExtra("result"));
}
});
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity028.this,MainActivity029.class);
intent.putExtra("loginname",txtname.getText().toString());
intentActivityResultLauncher.launch(intent);
}
});
}
}