小编Gab*_*bor的帖子

使用Retrofit 2进行记录

我正在尝试获取请求中发送的确切JSON.这是我的代码:

OkHttpClient client = new OkHttpClient();
client.interceptors().add(new Interceptor(){
   @Override public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
      Request request = chain.request();
      Log.e(String.format("\nrequest:\n%s\nheaders:\n%s",
                          request.body().toString(), request.headers()));
      com.squareup.okhttp.Response response = chain.proceed(request);
      return response;
   }
});
Retrofit retrofit = new Retrofit.Builder()
   .baseUrl(API_URL)
   .addConverterFactory(GsonConverterFactory.create())
   .client(client).build();
Run Code Online (Sandbox Code Playgroud)

但我只在日志中看到这个:

request:
com.squareup.okhttp.RequestBody$1@3ff4074d
headers:
Content-Type: application/vnd.ll.event.list+json
Run Code Online (Sandbox Code Playgroud)

我怎么做正确的记录,考虑到拆除setLog()setLogLevel()我们使用了改造1使用哪个?

java retrofit retrofit2 okhttp3

287
推荐指数
8
解决办法
14万
查看次数

HAXM和Lollipop

SDK升级到Android 5后,我无法使用英特尔硬件加速执行管理器:

$ android-sdk-macosx/tools/emulator -avd AVD_for_LowMemoryDevice_by_User -netspeed full -netdelay none -gpu on
HAX is working and emulator runs in fast virt mode    
emulator: VCPU shutdown request

EAX=80000001 EBX=019a0000 ECX=c0000080 EDX=00000000
ESI=00013c40 EDI=01d9d000 EBP=00100000 ESP=004f6104
EIP=001000f0 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0018 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0010 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0018 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0018 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0018 00000000 ffffffff 00c09300 DPL=0 …
Run Code Online (Sandbox Code Playgroud)

haxm android-5.0-lollipop

36
推荐指数
5
解决办法
2万
查看次数

Android中的静态单例生存期

我有一些不清楚的情况:

在最后一次参考持有活动被破坏后,静态单例是否会被垃圾收集?因为Application中没有对单例实例的引用.那么我可以依靠单身人士吗?

通过官方Android文档:

通常不需要子类Application.在大多数情况下,静态单例可以以更模块化的方式提供相同的功能.

通过一些帖子:

https://web.archive.org/web/20160729201921/http://www.devahead.com/blog/2011/06/extending-the-android-application-class-and-dealing-with-singleton/

在开发应用程序时,我发现有时一些绑定到活动的静态变量恰好是未初始化的,即使它们之前已被初始化!我认为当一个静态变量被初始化时,它在应用程序的整个生命周期中都是如此,但事实并非如此.

换句话说,如果没有任何东西对我的静态单例类进行引用,那么是什么阻止它被垃圾收集和销毁?

singleton android

27
推荐指数
2
解决办法
2万
查看次数

具有Retrofit 2的多个转换器

我有一个HATEOAS(HAL) REST服务并设法与下面的代码交谈(使用halarious作为转换引擎)但是当我尝试合并转换器(stallonestallone2)时,应用程序将总是拿起第一个转换器,而不是适合于响应类型的那个当然会导致错误.

我怎么能避免只在小型细节中有所不同的重复改造?

public interface Stallone {
   @GET("/discovery")
   Call<DiscoveryResponse> discover();
   @POST()
   Call<LoginResponse> login(@Url String url, @Body LoginRequest secret);
}
Run Code Online (Sandbox Code Playgroud)
   public static void main(String... args) throws IOException {
      // Initialize a converter for each supported (return) type
      final Stallone stallone = new Retrofit.Builder()
         .baseUrl(BASE)
         .addConverterFactory(HALConverterFactory.create(DiscoveryResponse.class))
         .build().create(Stallone.class);
      final Stallone stallone2 = new Retrofit.Builder()
         .baseUrl(BASE)
         .addConverterFactory(HALConverterFactory.create(LoginResponse.class))
         .build().create(Stallone.class);

      // Follow the HAL links
      Response<DiscoveryResponse> response = stallone.discover().execute();
      System.out.println(response.code() + " " + response.message());
      Assert.assertNotNull(response.body());
      String …
Run Code Online (Sandbox Code Playgroud)

java generics hateoas gson retrofit

17
推荐指数
1
解决办法
9459
查看次数

Android:标题栏和ActionBar之间有什么区别

我不知道他们是否是同一个东西,他们似乎有不同的方法去除它们但我不确定这些只是多种方法来做同样的事情.

那么有什么区别,如果有什么呢?

参考:

android titlebar android-actionbar

16
推荐指数
1
解决办法
8778
查看次数

12
推荐指数
1
解决办法
6000
查看次数

Android模拟器 - 无法加载驱动程序

在Ubuntu上运行,我收到此错误:

Cannot launch AVD in emulator.
Output:
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  155 (GLX)
  Minor opcode of failed request:  6 (X_GLXIsDirect)
  Serial number of failed request:  55
  Current serial number in output stream:  54
Run Code Online (Sandbox Code Playgroud)

平台工具是最新的.

模拟器图像使用https://dl.google.com/android/repository/sys-img/google_apis/x86_64-24_r08.zip它在Android N上.

更新(2016年12月2日): @Sébastien的解决方案不再有效但给出: …

linux android android-emulator

10
推荐指数
2
解决办法
2754
查看次数