可以使用以下方法开始从LocationManager检索通知:
requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener, Looper looper)
Run Code Online (Sandbox Code Playgroud)
文档使用以下单词解释属性:
provider the name of the provider with which to register
minTime minimum time interval between location updates, in milliseconds
minDistance minimum distance between location updates, in meters
listener a LocationListener whose onLocationChanged(Location) method will be called for each location update
looper a Looper object whose message queue will be used to implement the callback mechanism, or null to make callbacks on the calling thread
Run Code Online (Sandbox Code Playgroud)
如果我想用这种方法开始接收更新,我无法理解类(looper)的行为.
此外,我正在类LocationManager创建一个库,在执行正常行为之前,我需要做一些其他的工作.比我需要的是开始接收库的LocationListener上的更新,并且只有在验证某些条件时才执行正常行为.
为了做到这一点,我需要知道如果用户开始使用上述方法接收更新,将如何模拟具有LocationManager的行为.
我希望我很清楚.有人能帮我吗?谢谢!
我的应用程序有问题,我正在实现Tabs导航,我也想要一个导航抽屉.问题是,老实说,我不知道如何正确地做到这一点,我已经使用了developers.android.com上给出的示例,但它没有使用ViewPager.如果我在另一个应用程序中使用它,它的效果很好
我的LogCat是这样的:
11-13 15:47:38.096: E/FragmentManager(15675): No view found for id 0x7f070043 (com.videotrafico:id/content_frame) for fragment PlanetFragment{41f34380 #0 id=0x7f070043}
11-13 15:47:38.096: E/FragmentManager(15675): Activity state:
11-13 15:47:38.116: E/FragmentManager(15675): Local FragmentActivity 41ed6cd0 State:
11-13 15:47:38.116: E/FragmentManager(15675): mCreated=falsemResumed=false mStopped=false mReallyStopped=false
11-13 15:47:38.126: E/FragmentManager(15675): mLoadersStarted=false
11-13 15:47:38.126: E/FragmentManager(15675): FragmentManager misc state:
11-13 15:47:38.126: E/FragmentManager(15675): mActivity=com.videotrafico.MainActivity@41ed6cd0
11-13 15:47:38.126: E/FragmentManager(15675): mContainer=android.support.v4.app.FragmentActivity$2@41ed8638
11-13 15:47:38.126: E/FragmentManager(15675): mCurState=1 mStateSaved=false mDestroyed=false
11-13 15:47:38.126: E/FragmentManager(15675): View Hierarchy:
11-13 15:47:38.126: E/FragmentManager(15675): com.android.internal.policy.impl.PhoneWindow$DecorView{41ed91c8 V.E..... ... 0,0-0,0}
11-13 15:47:38.126: E/FragmentManager(15675): android.widget.LinearLayout{41ed99d0 V.E..... ... 0,0-0,0}
11-13 15:47:38.126: …Run Code Online (Sandbox Code Playgroud) 假设我有这个代码:
public HttpResponse myFunction(...) {
final HttpResponse resp;
OnResponseCallback myCallback = new OnResponseCallback() {
public void onResponseReceived(HttpResponse response) {
resp = response;
}
};
// launch operation, result will be returned to myCallback.onResponseReceived()
// wait on a CountDownLatch until operation is finished
return resp;
}
Run Code Online (Sandbox Code Playgroud)
显然我无法从onResponseReceived为resp赋值,因为它是一个最终变量,但如果它不是最终变量onResponseReceived则看不到它.那么,如何从onResponseReceived为resp赋值?
我想的是创建一个封装resp对象的包装类.最后一个对象将是这个包装类的一个实例,我可以将值赋给resp处理最终类中的对象(这不是最终的).
代码就是这个:
class ResponseWrapper {
HttpResponse resp = null;
}
public HttpResponse myFunction(...) {
final ResponseWrapper respWrap = new ResponseWrapper();
OnResponseCallback myCallback = new OnResponseCallback() {
public void onResponseReceived(HttpResponse response) {
respWrap.resp = response; …Run Code Online (Sandbox Code Playgroud) 好奇而已。类 URLConnection 需要有两个不同的超时是否有充分的理由?
该connectTimeout是在毫秒的最长等待时间,同时连接。如果在建立连接之前超时已过,则连接到服务器将失败并显示 SocketTimeoutException。
这readTimeout是在放弃之前等待输入流读取完成的最长时间。如果在数据可用之前超时已过,则读取将失败并显示 SocketTimeoutException。
你能给我一个很好的理由为什么这两个值应该不同吗?为什么调用需要更多时间来执行连接而不是接收一些数据(反之亦然)?
我问这个是因为我必须配置这些值,我的想法是为两者设置相同的值。