BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / mobile-terminal-at / #33320同步于 2017/7/25
该镜像源已超过 30 天没有更新,可能在源站已被删除。
MobileTerminalAT机器人发帖

Android studio没有hwbinder

Hogwarts
2017/7/25镜像同步9 回复
使用Android studio进行安卓开发的时候,利用parcelable进行传递值对象,日志显是无法发现hwbinder接口。 [ema12] 信息发起者为MainActivity.java,目标为Target.java 传递数据为User对象,数据:name="Hogwarts",age=1 具体的代码如下: 自己创建的简单的User类,用于传递 package com.example.parcelable1; import android.os.Parcel; import android.os.Parcelable; import java.io.Serializable; public class User implements Parcelable{ private String name; private int age; public int getAge() { return age; } public String getName() { return name; } public User(String name,int age) { this.name=name; this.age=age; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel parcel, int i) { parcel.writeInt(getAge()); parcel.writeString(getName()); } public static final Creator<User> CREATOR=new Creator<User>() { @Override public User createFromParcel(Parcel parcel) { return new User(parcel.readString(),parcel.readInt()); } @Override public User[] newArray(int i) { return new User[i]; } }; } MainActivity.java: package com.example.parcelable1; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i=new Intent(MainActivity.this, Target.class); i.putExtra("user",new User("Hogwarts",1)); startActivity(i); } }); } } Target.java package com.example.parcelable1; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class Target extends AppCompatActivity { private TextView t; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_target); Intent i =getIntent(); t=(TextView)findViewById(R.id.textview); // User user=(User)i.getSerializableExtra("user"); User user=i.getParcelableExtra("user"); t.setText(String.format("User:\n name=%s\n age=%d",user.getName(),user.getAge())); } } activity_main.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.parcelable1.MainActivity"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Send" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" android:textAllCaps="false" /> </android.support.constraint.ConstraintLayout> activity_target.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.parcelable1.Target"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textview" /> </android.support.constraint.ConstraintLayout> 结果name="",age=7274568 但是使用Serializable接口实现信息传递就没有问题[ema1][ema1]
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
Hogwarts机器人#1 · 2017/7/25
日志,,,,: 07-25 03:04:25.823 3645-3645/? I/zygote: Not late-enabling -Xcheck:jni (already on) 07-25 03:04:25.833 3645-3645/? W/zygote: Unexpected CPU variant for X86 using defaults: x86//这一行 07-25 03:04:25.854 3645-3652/? I/zygote: Debugger is no longer active 07-25 03:04:26.021 3645-3645/? I/InstantRun: starting instant run server: is main process 07-25 03:04:30.077 3645-3790/com.example.parcelable1 D/OpenGLRenderer: HWUI GL Pipeline 07-25 03:04:30.133 3645-3790/com.example.parcelable1 I/OpenGLRenderer: Initialized EGL, version 1.4 07-25 03:04:30.133 3645-3790/com.example.parcelable1 D/OpenGLRenderer: Swap behavior 1 07-25 03:04:30.133 3645-3790/com.example.parcelable1 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...//这一行 07-25 03:04:30.134 3645-3790/com.example.parcelable1 D/OpenGLRenderer: Swap behavior 0 07-25 03:04:30.166 3645-3790/com.example.parcelable1 D/EGL_emulation: eglCreateContext: 0xb2b91be0: maj 3 min 0 rcv 3 07-25 03:04:30.245 3645-3790/com.example.parcelable1 D/EGL_emulation: eglMakeCurrent: 0xb2b91be0: ver 3 0 (tinfo 0xb2b8b630) 07-25 03:04:30.246 3645-3790/com.example.parcelable1 E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf //这个 07-25 03:04:30.246 3645-3790/com.example.parcelable1 E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824 //这个 07-25 03:04:30.311 3645-3790/com.example.parcelable1 W/android.hardware.graphics.mapper@2.0::Mapper: getService: found null hwbinder interface //这一行 07-25 03:04:30.338 3645-3790/com.example.parcelable1 I/vndksupport: sphal namespace is not configured for this process. Loading /system/lib/hw/gralloc.ranchu.so from the current namespace instead. 07-25 03:04:30.433 3645-3790/com.example.parcelable1 D/EGL_emulation: eglMakeCurrent: 0xb2b91be0: ver 3 0 (tinfo 0xb2b8b630) 07-25 03:04:32.307 3645-3790/com.example.parcelable1 D/EGL_emulation: eglMakeCurrent: 0xb2b91be0: ver 3 0 (tinfo 0xb2b8b630) 07-25 03:04:32.341 3645-3790/com.example.parcelable1 D/EGL_emulation: eglMakeCurrent: 0xb2b91be0: ver 3 0 (tinfo 0xb2b8b630) 07-25 03:04:32.366 3645-3790/com.example.parcelable1 D/EGL_emulation: eglMakeCurrent: 0xb2b91be0: ver 3 0 (tinfo 0xb2b8b630) 07-25 03:04:32.402 3645-3790/com.example.parcelable1 I/chatty: uid=10092(u0_a92) RenderThread identical 1 line 07-25 03:04:32.457 3645-3790/com.example.parcelable1 D/EGL_emulation: eglMakeCurrent: 0xb2b91be0: ver 3 0 (tinfo 0xb2b8b630) 07-25 03:04:32.465 3645-3790/com.example.parcelable1 D/OpenGLRenderer: endAllActiveAnimators on 0xa705f900 (RippleDrawable) with handle 0xb2b92b00
lycxy机器人#2 · 2017/7/25
老铁,我猜是你把读和写的顺序不一致,你写的时候第一个是int,第二个是string,但是你读的时候反过来了。你修改一个你的creatFromParcel返回的User里面的参数顺序再试试
Hogwarts机器人#3 · 2017/7/25
【 在 lycxy 的大作中提到: 】 : 老铁,我猜是你把读和写的顺序不一致,你写的时候第一个是int,第二个是string,但是你读的时候反过来了。你修改一个你的creatFromParcel返回的User里面的参数顺序再试试 [ema2][ema2]真的是这样哎,谢谢[ema11][ema11][ema1][ema1]自己找了好几天错,原来是这里[ema8][ema8] 果然不懂方法很可怕
lycxy机器人#4 · 2017/7/25
出错的时候,直接去csdn找解决办法,大佬超级多
Hogwarts机器人#5 · 2017/7/25
【 在 lycxy 的大作中提到: 】 : 出错的时候,直接去csdn找解决办法,大佬超级多 嗯嗯,其实是在csdn和博客园看了下的,要不然也不会跑到论坛来
w350053002机器人#6 · 2017/8/2
parcelable 一直用插件生成的[ema36]
dss886机器人#7 · 2017/8/6
如果只是为了intent传递对象的话,用parcelable真没必要。。。搞个内存缓存都行
cowfighting机器人#8 · 2017/8/7
内存缓存放哪呢... applicaiton里面么? 【 在 dss886 的大作中提到: 】 : 如果只是为了intent传递对象的话,用parcelable真没必要。。。搞个内存缓存都行
dss886机器人#9 · 2017/8/7
在要启动的Acitivty内放一个public static变量,启动以后读intent的时候把这个变量存为成员变量,然后静态变量清空 这样的话可以省掉对象序列化和反序列化的过程,一般在对象比较大的时候有用 【 在 cowfighting 的大作中提到: 】 : 内存缓存放哪呢... applicaiton里面么? :