原文: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. 【面试 redis】【第十二篇】redis的相关面试问题

    redis的相关面试问题 redis教程:http://www.redis.net.cn/tutorial/3501.html ==================================== ...

  2. mac环境下intellij的自定义配置文件位置

    ~/Library/Preferences/IntelliJIdea2017.2/

  3. 《Attention is All You Need》

    https://www.jianshu.com/p/25fc600de9fb 谷歌最近的一篇BERT取得了卓越的效果,为了研究BERT的论文,我先找出了<Attention is All You ...

  4. 理解TIME_WAIT

    理解TIME_WAIT http://www.firefoxbug.com/index.php/archives/2795/ 理解TIME_WAIT(2) http://www.firefoxbug. ...

  5. 转 c#中stringbuilder的使用

    String   对象是不可改变的.每次使用   System.String   类中的方法之一时,都要在内存中创建一个新的字符串对象,这就需要为该新对象分配新的空间.在需要对字符串执行重复修改的情况 ...

  6. Android 利用二次贝塞尔曲线模仿购物车加入物品抛物线动画

    Android 利用二次贝塞尔曲线模仿购物车加入物品抛物线动画 0.首先.先给出一张效果gif图. 1.贝塞尔曲线原理及相关公式參考:http://www.jianshu.com/p/c0d7ad79 ...

  7. 20151028整理罗列某种开发所包括对技术(技术栈),“较为全面”地表述各种技术大系的图表:系统开发技术栈图、Web前端技术栈图、数据库技术栈图、.NET技术栈图

    ———————————— 我的软件开发生涯 (10年开发经验总结和爆栈人生) 爆栈人生 现在流行说全栈.每种开发都有其相关的技术.您是否觉得难以罗列某种开发所包括对技术(技术栈)呢?   您是否想过: ...

  8. Java中使用FileputStream导致中文乱码问题的修改方案

    package com.pocketdigi; import java.io.File; import java.io.FileInputStream; import java.io.FileOutp ...

  9. Windows 8系统默认开启的.Net Framework版本是4.0,而部分用户可能需要使用到3.5或以下版本,简单添加方法

    从网络途径下载的.Net Framework3.5是无法直接在Windows 8系统上安装的,我们可以通过Windows 8的添加功能来实现 1.打开控制面板,点击”启用或关闭Windows 功能“ ...

  10. Git教程学习(二)

    教程来自: Git教程(廖雪峰的官方网站) 主要命令: $ git log #查看已提交内容 $ git log --pretty=oneline #查看已提交内容(紧凑版) $ git reset ...