问题
I am using this app as a framework and trying to pass an object to my own UI Phone Call .
But when I try to put my object into myAdapter
:
Call.putExtra("itemObject", items.get(position));
I get a BadParcelableException
error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.server.telecom/com.android.server.telecom.components.UserCallActivity}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.example.aliton.customphonecall.itemObject
Question: How do I pass my object to CallActivity
?
In order to make it a bit more clear, I want to pass my object via a Button
in myAdapter
.
As can be seen below, the Button
track first goes from myAdapter
to CallService
and inside CallService
is called CallActivity
.
Then I thought I could pass my object to CallService
and pass again my object to CallActivity
.
I/debinf Adapter: Requesting Call
I/debinf CallService: onCallAdded
I/debinf OngoingCall: call.getState() is 9
I/debinf CallService: starting CallActivity
I/debinf CallActivity: onCreate
I/debinf OngoingCall: state is 1
I/debinf OngoingCall: state is 4
Here is myAdapter
:
public class myAdapter extends BaseAdapter {
private ArrayList<itemObject> items;
private Context context;
public myAdapter(ArrayList<itemObject> items, Context context) {
this.items = items;
this.context = context;
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int position) {
return items.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.item_call, parent, false);
TextView mName = (TextView) view.findViewById(R.id.item_name);
TextView mId = (TextView) view.findViewById(R.id.item_id);
final TextView mPhone = (TextView) view.findViewById(R.id.item_phone);
ImageButton mCall = (ImageButton) view.findViewById(R.id.item_call);
mName.setText(items.get(position).getName());
mId.setText(items.get(position).getId());
mPhone.setText(items.get(position).getPhone());
mCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("tel:"+mPhone.getText().toString().trim());
Intent Call = new Intent(Intent.ACTION_CALL, uri);
Call.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Call.putExtra("itemObject", items.get(position));
Log.i("debinf Adapter", "Requesting Call");
context.startActivity(Call);
}
});
return view;
}
}
Here is my CallService
:
public class CallService extends InCallService {
@Override
public void onCallAdded(Call call) {
super.onCallAdded(call);
Log.i("debinf CallService", "onCallAdded");
new OngoingCallObject().setCall(call);
Log.i("debinf CallService", "starting CallActivity");
Intent CallAct = new Intent(this, CallActivity.class);
CallAct.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
CallAct.setData(call.getDetails().getHandle());
startActivity(CallAct);
//CallActivity.start(this, call);
}
@Override
public void onCallRemoved(Call call) {
super.onCallRemoved(call);
Log.i("debinf CallService", "onCallRemoved");
new OngoingCallObject().setCall(null);
}
}
I want to use my object to fill the TextView
on the upper left part of CallActivity
.
Here is DialerAcitivity
image.
I appreciate any help.
来源:https://stackoverflow.com/questions/55620683/android-studio-pass-parcelable-data-to-call-service-phone-call-app