与(跨进程)Android中的自定义内容提供商的异常处理 [英] Dealing with (cross-process) exceptions in Android custom content provider

查看:138
本文介绍了与(跨进程)Android中的自定义内容提供商的异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序,效果相当好自定义内容提供商。我希望其他应用程序也访问我的内容提供商。我想一些干净的沟通方式异常和错误,但据我可以告诉Android的内容提供商框架没有提供任何方式传播跨越进程的例外。

I have a custom content provider in my Android app that works reasonably well. I expect other apps to also access my content provider. I would like some clean way to communicate exceptions and errors, but as far as I can tell the Android content provider framework doesn't provide any way to propagate exceptions across processes.

我应该如何指示异常状态,以手机号码?我必须以某种方式连接$ C C $它进入我的返回数据,并依赖于客户端来检查呢?有什么方法吗?如果编码成普通的返回数据是,什么是最好的方法是什么? (我可以看到一些为光标查询调用返回的替代品,但对于乌里插入或 INT 按<$ C $返回C>更新或删除?)

How should I indicate an exception state to my caller? Do I have to somehow encode it into my returned data and rely on clients to check for it? Is there any alternative? If encoding into the ordinary return data is it, what's the best way? (I can see a number of alternatives for the Cursor returned by a query call, but what about the Uri returned by insert, or the int returned by update or delete?)

推荐答案

还有就是的RuntimeException 子类的简短列表,如果扔在供应商,将重新扔在一个客户端应用程序。它们是:

There is a short list of RuntimeException subclasses which, if thrown in the provider, will be re-thrown in a client app. These are:

  • IllegalStateException异常
  • 抛出:IllegalArgumentException
  • NullPointerException异常
  • SecurityException异常
  • BadParcelableException
  • IllegalStateException
  • IllegalArgumentException
  • NullPointerException
  • SecurityException
  • BadParcelableException

来源:创建内容提供商提到 IAE NPE ;我猜别人会工作的基础上<一个href="http://developer.android.com/reference/android/os/Parcel.html#writeException%28java.lang.Exception%29">the Javadoc中 Parcel.writeException

Source: Creating Content Providers mentions IAE and NPE; I guessed that the others would work based on the Javadoc forParcel.writeException.

客户端应用程序将只得到详细消息,而不是一个堆栈跟踪或导致堆栈。对于特殊状态,可连接codeD插入字符串(详细信息),这是一个合理的选择。

The client app will only get the detail message, not a stack trace or the cause stack. For exceptional state which can be encoded into a String (the detail message), this is a reasonable choice.

我在其他解决方案仍然感兴趣了。

I'm still interested in other solutions, too.

这篇关于与(跨进程)Android中的自定义内容提供商的异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆