原文: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
  • 1
    Hi @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的更多相关文章

  1. loadView在App启动时到底都干了些什么?

    loadView在App启动时到底都干了些什么? 查阅苹果官方文档如下: 1. 当你访问一个ViewController的view属性时,如果此时view的值是nil,那么,ViewControlle ...

  2. Android开发,在Activity启动时,默认隐藏软键盘。和遮挡Edittext时的处理

    在Activity启动时,默认隐藏软键盘: 在AndroidManifest.xml中找到你得Activity ,为它添加属性: android:windowSoftInputMode="s ...

  3. 避免git clone和push时每次都需要输入用户名和密码

    有三种方式解决git clone时每次都需要输入用户名和密码, 1. SSH免密方式 使用git bash ssh-keygen或puttygen.exe生成公钥. 2. 配置全局开机存储认证信息 下 ...

  4. Git push 时每次都需要密码的疑惑

    2015.1.13更新: 在本地搭建Git服务器时,也是有每次操作需要密码的情况. 是因为每次做推送动作时,Git需要认证你是好人.所以需要密码. 可以在 /home/username/.ssh/au ...

  5. 消除 activity 启动时白屏、黑屏问题

    默认情况下 activity 启动的时候先把屏幕刷成白色,再绘制界面,绘制界面或多或少有点延迟,这段时间中你看到的就是白屏,显然影响用户体验,怎么消除呢? 在 Activity theme 设置sty ...

  6. vs2017 mvc 启动时经常出现调用的目标发生异常

    1.vs  2017 调试web 程序时老是出现调用的目标发生异常 本人眼拙,基本上看了网站说的一些方法,设置环境变量是无效的,只有一个办法,卸载重装. 1.0 卸载过程 打开计算机-卸载或更改软件- ...

  7. 改变Activity启动时的默认动画

    why 在开发中我们可能需要改变这一行为,一般基于2种理由: 产品的spec这么要求的: 想自己控制这个行为,因为在Android设备上可能每个的这一默认行为都不一样,厂商可以很容易修改它,从而导致a ...

  8. vue 进入页面每次都调用methods里的方法

    // 监听路由,每次进入页面调用方法,放在method里 mounted(){ this.getPath() }, methods: { getPath(){ console.log(this.$ro ...

  9. selenium+firefox时每次都要导入数据解决方法解决方法:

    火狐录制组件:selenium-ide-2.9.0.xpiselenium1调试c#前要运行服务器 selenium-server-standalone-2.47.1.jar导入引用压缩包seleni ...

随机推荐

  1. 斗鱼宣布获C轮15亿融资 直播行业进入资本时代

    今天,斗鱼直播宣布完成C轮15亿人民币融资,本轮融资由凤凰投资与腾讯领投,深创投.国家中小企业基金.红土成长等跟投.2016年3月,斗鱼曾获得1亿美元(约合6.7亿元人民币)B轮融资,腾讯出资4亿人民 ...

  2. Java中有哪些语法糖?

    不要你写汇编,Java句句是糖 不能同意上面的这句话,要说为什么,首先要定义下面要讲的“语法糖”. 语法糖指计算机语言中添加的某种语法,这种语法对语言的功能并没有影响,并没有给语言添加什么新东西,但是 ...

  3. JavaScript 编码规范(中文/Airbnb公司版)

    Airbnb 是一家位于美国旧金山的公司,本文是其内部的 JavaScript编码规范,写得比较全面,在 Github 上有 16,686 + Star,3,080 + fork,前端开发人员可参考. ...

  4. centos安装EPEL repo

    What is EPEL EPEL (Extra Packages for Enterprise Linux) is open source and free community based repo ...

  5. 如何将Revit明细表导出为Excel文档

    Revit软件没有将明细表直接导出为Excel电子表格的功能,Revit只能将明细表导出为TXT格式,但是这种TXT文件用EXCEL处理软件打开然后另存为XLS格式即可,以Revit2013版自带的建 ...

  6. JS中的HTML片段

    经常在js里面写一些html模板,但是由于语法不同,没有办法啊直接将html黏贴在js中. var html = "<!DOCTYPE html>"+ "&l ...

  7. scala recursive value x$5 needs type

    recursive value x$5 needs type的原因是使用了一个类型不确定的变量,例如 val (id, name) = (id, getName(id)) 其中id是个变量,其值还不确 ...

  8. 后台任务hangfire

    Installation¶ There are a couple of packages for Hangfire available on NuGet. To install Hangfire in ...

  9. PL/SQL学习笔记之数据类型中的标量、LOB

    一:标量 标量 即 基本数据类型,主要有4种:数值.字符.布尔类型.日期时间. 1:数值类型 数据类型 描述 PLS_INTEGER 通过2,147,483,647到-2147483648范围内有符号 ...

  10. OpenWrt 18.06.1的ss-redir, 以及在乐视超4 X40上看Youtube

    在18.06里面要设个透明代理, 就一直不成功 各种TIME OUT, PRIVATE SSL ERROR, 换回旧版的luci-app-shadowsocks也不行. 我就一直想, 到底这东西还能有 ...