Android开发笔记之:返回键的复写onBackPressed()介绍
时间:2022-04-29 17:54:40
在android开发中,当不满足触发条件就按返回键的时候,就要对此进行检测。尤其是当前Activity需要往前一个Activity传送消息时。即Activity1跳转到Activity3如果采用的是startActivityForResult这种方式,如果不重写返回键,程序不知道要返回给Activity1什么内容就会报错。因此,必须对Activity3的返回按键重写,这里让他传一个“ERROR”信息:
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
Intent backIntent = new Intent(Activity3.this, Activity1.class);
Bundle bundle = new Bundle();
if(!clickOk)
bundle.putString("send", "ERROR");
backIntent.putExtras(bundle);
Activity3.this.setResult(1, backIntent);
Activity3.this.finish();
//super.onBackPressed();
}
标签:返回键,复写,onBackPressed
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java中日期格式化的大坑
2021-07-02 09:42:59
Java Runnable和Thread实现多线程哪个更好你知道吗
2021-08-17 05:48:50
Java基于分治法实现的快速排序算法示例
2023-12-15 07:39:06
![](https://img.aspxhome.com/file/2023/2/66642_0s.jpg)
springboot整合spring-retry的实现示例
2022-01-13 01:25:53
![](https://img.aspxhome.com/file/2023/0/80170_0s.png)
Android NDK开发(C语言-文件读写)
2022-07-04 17:02:09
Spring Cloud Gateway替代zuul作为API网关的方法
2023-05-03 07:19:58
![](https://img.aspxhome.com/file/2023/8/69738_0s.jpg)
SpringBoot 自定义starter yaml提示失效问题及解决方法
2022-08-03 14:58:42
![](https://img.aspxhome.com/file/2023/5/70945_0s.jpg)
C#实现微信分账功能的完整步骤
2022-10-24 17:43:46
![](https://img.aspxhome.com/file/2023/2/81132_0s.png)
Java持久化框架Hibernate与Mybatis优劣及选择详解
2023-12-03 19:46:14
Java多线程死锁与资源限制操作
2023-08-31 05:54:30
SpringBoot 集成 activiti的示例代码
2023-01-22 10:22:03
![](https://img.aspxhome.com/file/2023/8/62238_0s.png)
C#中ListView控件实现窗体代码
2023-02-04 02:55:06
SpringBoot整合Redisson实现分布式锁
2021-08-01 12:04:35
![](https://img.aspxhome.com/file/2023/8/82458_0s.png)
C#使用Process类调用外部程序分解
2022-01-07 16:34:11
详解Java接口签名(Signature)实现方案
2022-02-05 09:28:57
![](https://img.aspxhome.com/file/2023/4/72594_0s.jpg)
深入探讨Linux静态库与动态库的详解(一看就懂)
2023-07-04 01:02:28
Java栈和基础队列的实现详解
2023-07-02 05:36:59
![](https://img.aspxhome.com/file/2023/7/61597_0s.gif)
浅析Java多线程同步synchronized
2023-05-20 15:52:29
Android AndBase框架使用封装好的函数完成Http请求(三)
2021-09-15 09:49:56
Spring中自定义数据类型转换的方法详解
2022-10-09 02:56:51