保证Activity启动时每次都调用create
原文:https://stackoverflow.com/questions/41766547/run-oncreate-every-time-android-app-is-opened
If you want only onCreate() to be called everytime, then you must remove from recents when home is pressed. For that you need to make changes in Manifest fie for the activity.Try using the below for the activity inManifets :
android:clearTaskOnLaunch="true" android:finishOnTaskLaunch="true"
- I will try number 2. Number 1 is not an option as the code in onResume does not work the way it does in onCreate (same code). – Laura Jan 20 '17 at 21:57
- Yes. It will work..!! Hope it helped. – Aparna Venkata Jan 21 '17 at 1:25
- Unfortunately, this does not work for me. – Laura Jan 23 '17 at 9:54
- 1Hi @Laura, just try using "android:noHistory="true" in you manifest under that activity. This will for sure work. – Aparna Venkata Jan 23 '17 at 16:22
- In combination with clearTaskOnLaunch and finishOnTaskLaunch or not? I will try this tomorrow, thank you. – Laura Jan 24 '17 at 7:33
- Yes. Let me know if it worked – Aparna Venkata Jan 25 '17 at 8:04
- This worked for me! OnCreate is executed every time. Thank you! – Laura Jan 25 '17 at 9:34
- If only this worked with an activity that was started for result... – Laura Jan 25 '17 at 12:49
- It will work for any activity. Declare in Manifest for the next activity that is started for result. – Aparna Venkata Jan 25 '17 at 13:41
- I worked around this problem. Android documentation: Whether or not the activity should be removed from the activity stack and finished (its finish() method called) when the user navigates away from it and it's no longer visible on screen — "true" if it should be finished, and "false" if not. In this case, onActivityResult() is never called if you start another activity for a result from this activity.... So that is why– Laura Jan 25 '17 at 14:20
保证Activity启动时每次都调用create的更多相关文章
- loadView在App启动时到底都干了些什么?
loadView在App启动时到底都干了些什么? 查阅苹果官方文档如下: 1. 当你访问一个ViewController的view属性时,如果此时view的值是nil,那么,ViewControlle ...
- Android开发,在Activity启动时,默认隐藏软键盘。和遮挡Edittext时的处理
在Activity启动时,默认隐藏软键盘: 在AndroidManifest.xml中找到你得Activity ,为它添加属性: android:windowSoftInputMode="s ...
- 避免git clone和push时每次都需要输入用户名和密码
有三种方式解决git clone时每次都需要输入用户名和密码, 1. SSH免密方式 使用git bash ssh-keygen或puttygen.exe生成公钥. 2. 配置全局开机存储认证信息 下 ...
- Git push 时每次都需要密码的疑惑
2015.1.13更新: 在本地搭建Git服务器时,也是有每次操作需要密码的情况. 是因为每次做推送动作时,Git需要认证你是好人.所以需要密码. 可以在 /home/username/.ssh/au ...
- 消除 activity 启动时白屏、黑屏问题
默认情况下 activity 启动的时候先把屏幕刷成白色,再绘制界面,绘制界面或多或少有点延迟,这段时间中你看到的就是白屏,显然影响用户体验,怎么消除呢? 在 Activity theme 设置sty ...
- vs2017 mvc 启动时经常出现调用的目标发生异常
1.vs 2017 调试web 程序时老是出现调用的目标发生异常 本人眼拙,基本上看了网站说的一些方法,设置环境变量是无效的,只有一个办法,卸载重装. 1.0 卸载过程 打开计算机-卸载或更改软件- ...
- 改变Activity启动时的默认动画
why 在开发中我们可能需要改变这一行为,一般基于2种理由: 产品的spec这么要求的: 想自己控制这个行为,因为在Android设备上可能每个的这一默认行为都不一样,厂商可以很容易修改它,从而导致a ...
- vue 进入页面每次都调用methods里的方法
// 监听路由,每次进入页面调用方法,放在method里 mounted(){ this.getPath() }, methods: { getPath(){ console.log(this.$ro ...
- selenium+firefox时每次都要导入数据解决方法解决方法:
火狐录制组件:selenium-ide-2.9.0.xpiselenium1调试c#前要运行服务器 selenium-server-standalone-2.47.1.jar导入引用压缩包seleni ...
随机推荐
- 转载: ASP.NET Core入门系列文章
今天在网上发现了ithome上的asp.net core 系列文章,对于新手入门还不错,这里转载一下,也方便查阅. [Day01] 從頭開始 [Day02] 程式生命週期 (Application L ...
- FMDB使用简介
转:http://my.oschina.net/youzaiyouzaie/blog/92325 源码地址:https://github.com/ccgus/fmdb 这次要分享的是在iOS中使用SQ ...
- html5中页面拨打电话的方式
<a href="tel:18688888888">拨号</a> <a href="sms:18688888888">发短信 ...
- 安装NVIDIA驱动时禁用自带nouveau驱动
安装英伟达驱动时,一般需要禁用自带nouveau驱动,按如下命令操作: sudo vim /etc/modprobe.d/blacklist-nouveau.conf 添加如下内容: blacklis ...
- boost.xml_parser中文字符问题 (转)
当使用xml_parser进行读xml时,如果遇到中文字符会出现解析错误. 网上有解决方案说使用wptree来实现,但当使用wptree来写xml时也会出错.而使用ptree来写中文时不会出错. 综合 ...
- Java 对字符串数据进行MD5/SHA1哈希散列运算
Java对字符串数据进行MD5/SHA1哈希散列运算 [java] view plain copy package cn.aibo.test; import java.security.Message ...
- JS中的HTML片段
经常在js里面写一些html模板,但是由于语法不同,没有办法啊直接将html黏贴在js中. var html = "<!DOCTYPE html>"+ "&l ...
- 【java】求两个字符串的最长公共子串
这个是华为OJ上的一道题目.首先,如果我们用java写代码,华为OJ有以下三条规则需遵守,否则编译无法通过或者用例无法通过,规则如下: (1)一定不可以有包名: (2)主类名只能为Main: (3)不 ...
- Effective Java 第三版——56. 为所有已公开的API元素编写文档注释
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- windows系统安装完后要做的事情
完成之后 1.netplwiz关闭开机输入密码 2.这台电脑右击->属性->高级系统设置->高级->性能设置->高级->虚拟内存: 把C盘设为无分页文件,选择一个大 ...