原文: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. tmux分屏幕

    1. tmux  a  -t  fly 连接上tmux 2. 左右分屏幕,ctrl+a ,再按% 上下分屏: ctrl+a, 再按“ 切换屏幕: ctrl+a, 再按o 关闭终端: ctrl+a, 再 ...

  2. 微软BI 之SSIS 系列 - Lookup 中的字符串比较大小写处理 Case Sensitive or Insensitive

    开篇介绍 前几天碰到这样的一个问题,在 Lookup 中如何设置大小写不敏感比较,即如何在 Lookup 中的字符串比较时不区分大小写? 实际上就这个问题已经有很多人提给微软了,但是得到的结果就是 C ...

  3. 让WebService支持Get请求

    在C#中,新建一个webservice,默认是post类型的.如果需要支持Get请求,需要对web.config文件进行配置 <system.web> <compilation de ...

  4. asp.net core 2.1 post 无法提交参数?

    起 ,是微软二逼升级了.....不是说好了合并Controller 了吗?又倒回去了.................

  5. 如何在WCF中用TcpTrace工具查看发送和接收的SOAP消息

    WCF对消息加密(只对消息加密,不考虑Authorize)其实很简单,只要在server和client端的binding加入security mode为Message(还有Transport, Tra ...

  6. 新手如何学习 jQuery?

    可以看张晓菲的<锋利的jQuery>,重点是自己理解函数用法并自行实现一些常用的效果.如果需要快速查阅可以用这个api,每个函数都附有简单的示例:http://api.jquery.com ...

  7. 如何查看Apache的连接数和当前连接数

    查看Apache的连接数和当前的连接数以及IP访问次数,下面有个不错的示例,大家可以参考下,希望对大家解决问题有所帮助 查看了连接数和当前的连接数 复制代码 代码如下: netstat -ant | ...

  8. 针对个别utf8编码站点在iis7上浏览器编码不能自动识别的解决方法

    个别utf8编码站点在iis7上客户端浏览器编码不能自动识别的编号,输入仍为gbk2312,而不是utf-8,这样导致我们看到的网站为乱码. 要解决这个问题,有两个方法,一为打开网站以后,右键,选择编 ...

  9. linux每日命令(5):mkdir命令

    linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 1.命令格式: mkdir [选项] 目录名或路径名 2. ...

  10. GNU make使用(一)

    [时间:2017-01] [状态:Self] [关键词:makefile,gcc,编译,动态库,静态库,可执行文件,shell命令] 引言 前段时间在Linux下编写一个可测试的程序发现,我对make ...