Android服务错误处理(Android service error handling)
什么是服务错误处理的最佳方法? 例如,我有服务从Internt获取一些信息,我希望在连接错误时向用户显示一些带有消息的对话框。 或者,如果我有一些Util类用于我的服务使用的解析HTML,并且此Util类中发生异常。 如何显示对话框? 据我所知,DialogBuilder需要一些Activity上下文,但Service上下文是错误的。 对? 谢谢。
What is best way for services error handling? For example, I have service which get some information from Internt, I want show to user some dialog with message when connectivity is bad. Or if I have some Util class for parse HTML that used by my service and exception occures in this Util class. How to show dialog? As I know DialogBuilder needs some Activity context, but Service context is wrong for this. Right? Thanks.
原文:https://stackoverflow.com/questions/3696440
最满意答案
要在不触及工作树的情况下丢弃索引,您可以这样做:
git reset
这就是它的作用。 这相当于你的自我回答,“仅使用git命令”。 最终效果就像是将
git diff HEAD
的结果抛弃,将所有内容回滚到最顶层的提交,然后将该diff重新应用到HEAD
以重新创建原始工作树。但是假设您想要丢弃索引中的更改,以便实际从您的工作中减去这些丢弃的更改。 在这种情况下, 我会做的是使用交互式rebase来拼接更改:
git commit # commit the index git commit -a # commit the remaining changes git rebase --interactive HEAD^^ # rebase top two commits onto same branch
在出现的编辑器窗口中,我只是删除保存来自不需要的索引的不需要的更改的提交,然后保存并退出,让交互式rebase完成剩下的工作。 可能存在必须解决的合并冲突,因为先前未进行的所需更改可能取决于分阶段的不需要的更改。
最后,我会有一个提交,它只包含以前未经过更改的更改,并且不需要的更改也消失了。 那时,我可以摆脱那个提交,把它变成未分级的变化:
git reset HEAD^
或者只是保持提交并通过做更多的黑客攻击和
git commit --amend
来添加它并更新它的消息。
rebase --interactive
所做的一切(事实上,非交互式rebase确实)可以使用cherry-pick
命令完成,但它提供了方便的“工作流自动化”。对于涉及提交的重新排序,删除提交,将多个提交压缩为一个,重写提交消息(除最顶层补丁之外)以及类似事物的任何场景,知道如何使用交互式rebase是很好的。
我们的想法是将所有更改的表示形式转换为单独的提交,然后使用commit-munging kung-fu,最后在必要时“取消提交”某些内容。
对于复杂的事情,git在处理提交方面要比使用非分段更改或索引更好,后者是一些临时区域; 所以你想让你的工作离开那里并首先进入提交。 事实上,如果您有未分阶段或分阶段的更改,git会阻止您执行各种有用的操作。
让你的工作进入提交的一个原因是,在git中很容易永远丢失工作副本或索引。 工作副本和索引不是提交对象,因此无法从reflog中恢复它们。 输入错误的命令,消除其中一个或两个,它们就会消失。 但是,任何提交的更改都可以恢复,即使您丢失它们,通过reflog,或通过您可以设置的分支指针或标记。
What one can do is the following, using
git-diff
andpatch
:git diff HEAD > my.patch git reset --hard patch -p1 < my.patch
but there must be a better way using git commands only.
相关问答
更多-
这意味着您所做的部分更改是针对提交进行的,而部分则不是。 如果你运行,你可以检查什么是上演的 git diff --staged -- README.md 并检查运行中未分配的内容 git diff -- README.md 大多数版本控制系统通常只存储两种状态之间的变化。 git的工作方式,当你对一个文件进行多重更改时,你必须添加/标记它们中的每一个,作为一组更改(即提交)的一部分。 当你使用git add它会自动完成。 然而,它不是唯一的方法,你可以将你所有的个人变化(区块)添加到你的“索引”中。 ...
-
是的,真的有可能,相信与否, 双重STASH : 将您需要藏起来的所有文件放在一起。 运行git stash --keep-index 。 此命令将创建一个具有所有更改( 分段和未分段 )的存储,但会将分段更改保留在工作目录中(仍处于分段状态)。 运行git stash save "good stash" 现在你的"good stash" 只有分段文件 。 现在,如果您在存储之前需要未分类的文件,只需应用第一个存储( 使用--keep-index创建的文件),现在就可以将您所"good stash"文件删除 ...
-
git stash save有一个选项--keep-index ,它完全符合你所需要的。 所以,运行git stash save --keep-index 。 git stash save has an option --keep-index that does exactly what you need. So, run git stash save --keep-index.
-
另一个更快的方法是: git stash save --keep-index 之后,如果你喜欢,你可以用一个git stash drop命令删除该藏书。 Another quicker way is: git stash save --keep-index --include-untracked You don't need to include --include-untracked if you don't want to be thorough about it. After that, you ...
-
如果你看一下git status的输出,它实际上回答了这个问题: Davids-Mac-Pro:DAD dhoelzer$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD
..." to unstage) new file: t 因此,只需执行git reset HEAD 看来, bin/ls是一个子模块 。 当您进入此目录并运行git status您应该看到哪些内容被修改和未跟踪,您将能够将其提交到sumbodule的基本存储库中。 之后,当子模块的存储库的HEAD会有新的提交时,您可以在主存储库中git add此更改并在那里提交。 It appears, that bin/ls is a submodule. When you cd into this directory and run git status you should see what content is ...要在不触及工作树的情况下丢弃索引,您可以这样做: git reset 这就是它的作用。 这相当于你的自我回答,“仅使用git命令”。 最终效果就像是将git diff HEAD的结果抛弃,将所有内容回滚到最顶层的提交,然后将该diff重新应用到HEAD以重新创建原始工作树。 但是假设您想要丢弃索引中的更改,以便实际从您的工作中减去这些丢弃的更改。 在这种情况下, 我会做的是使用交互式rebase来拼接更改: git commit # commit the index git commit -a # ...在关于处理行结尾的github文章之后,你可以看到在.gitattributes文件上设置text = auto告诉git“以它认为最好的方式处理文件”。 看到文件的其余部分已被注释,并且您在text = auto上有一个星标,这适用于所有内容。 我认为,在你的情况下,git认为最好的,结果是错误的选择。 Following the github article on dealing with line endings you can see that setting text=auto on the .g ...在worktreeexample创建一个新文件,告诉git在哪里查看。 格式基于.git/worktrees的内容。 因此,对于上面的示例,这将起作用: echo "gitdir: /home/me/.git/worktrees/worktreeexample" > worktreeexample/.git 然后在worktreeexample/运行git status将显示所有已删除的文件,并希望您的工作正在进行中。 跑 cd worktreeexample git checkout -- . 这将只 ...使用远程分支在分阶段或非分阶段更改之间进行差异(Git diff between staged or unstaged changes with a remote branch)[2022-12-09]
是否有办法在分阶段更改和远程分支之间做一个git diff,比如origin / branch1。 赶紧跑: git diff --cached origin/branch1 (如果你喜欢,你可以使用--staged这里;我使用--cached因为git rm有--cached但不是--staged )。 这会向您显示一种更改origin/branch1以匹配您已暂存的内容的方法: $ git show origin/branch1:README initial version $ cat README ...相关文章
更多- 静态属性,直接把iis搞垮掉 Http error 503 Service Unavailable
- spring3MVC +spring security3 关于扩展UserDetailsService 无法注入service的疑问.
- eclipse里报:An internal error occurred during:
- SSH中action到service的错误
- Hadoop 异常记录 ERROR: org.apache.hadoop.hbase.MasterNotRunningException: Retried 7 times
- The connection to adb is down, and a severe error has occured.
- Web Service PHP入门示例
- 关于Service常驻内存不被清理的解决方法.
- RFC2848--The PINT Service Protocol: Extensions to SIP and SDP for IP Access to Telephone Call Services
- solr error logs org.apache.solr.common.SolrException: ERROR: [doc=17] unknown field alias
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。