Я пытаюсь отправить объект класса между двумя actvities с parcelable, кажется, что он хорошо применен, я реализовал parcelable и затем передал его через намерение, но мое приложение остановилось без каких-либо действий, мне нужна помощь !!
Это мой класс:
public class myTasks implements Parcelable {
String title_task, desc_task, prio_task, diff_task, date_task;
public myTasks(){
}
public myTasks(String title_task, String desc_task, String prio_task, String diff_task, String date_task) {
this.title_task = title_task;
this.desc_task = desc_task;
this.prio_task = prio_task;
this.diff_task = diff_task;
this.date_task = date_task;
}
protected myTasks(Parcel in) {
title_task = in.readString();
desc_task = in.readString();
prio_task = in.readString();
diff_task = in.readString();
date_task = in.readString();
}
public static final Creator<myTasks> CREATOR = new Parcelable.Creator<myTasks>() {
public myTasks createFromParcel(Parcel in) {
return new myTasks(in);
}
public myTasks[] newArray(int size) {
return new myTasks[size];
}
};
public String getTitle_task() {
return title_task;
}
public void setTitle_task(String title_task) {
this.title_task = title_task;
}
public String getDesc_task() {
return desc_task;
}
public void setDesc_task(String desc_task) {
this.desc_task = desc_task;
}
public String getPrio_task() {
return prio_task;
}
public void setPrio_task(String prio_task) {
this.prio_task = prio_task;
}
public String getDiff_task() {
return diff_task;
}
public void setDiff_task(String diff_task) {
this.diff_task = diff_task;
}
public String getDate_task() {
return date_task;
}
public void setDate_task(String date_task) {
this.date_task = date_task;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(title_task);
parcel.writeString(desc_task);
parcel.writeString(prio_task);
parcel.writeString(diff_task);
parcel.writeString(date_task);
}
}
Это источник Упражнение:
public class taskAdd extends AppCompatActivity {
TextView title_page, add_title, add_desc, add_date, add_prio, add_diff;
EditText title_task, desc_task, date_task, prio_task, diff_task;
//button
Button btn_save, btn_cancel;
ArrayList<myTasks> dataList;
//task counter
Integer task_num = new Random().nextInt();
String key_task = Integer.toString( task_num);
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_task_add);
//definition of the variables
title_page = findViewById(R.id.title_page);
add_title = findViewById(R.id.add_title);
add_desc = findViewById(R.id.add_desc);
add_date = findViewById(R.id.add_date);
add_prio = findViewById(R.id.add_prio);
add_diff = findViewById(R.id.add_diff);
title_task = findViewById(R.id.title_task);
desc_task = findViewById(R.id.desc_task);
date_task = findViewById(R.id.date_task);
prio_task = findViewById(R.id.prio_task);
diff_task = findViewById(R.id.diff_task);
btn_save = findViewById(R.id.btn_save);
btn_cancel = findViewById(R.id.btn_cancel);
/*#####################################################*/
//recuperation of data
btn_save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//fil the object item_task with data
myTasks task = new myTasks();
task.setTitle_task(title_task.getText().toString());
task.setDesc_task(desc_task.getText().toString());
task.setPrio_task(prio_task.getText().toString());
task.setDiff_task(diff_task.getText().toString());
task.setDate_task(date_task.getText().toString());
Log.i("TAG","Le titre de tâche est =" + " " +task.getTitle_task());
Intent intent = new Intent(taskAdd.this,MainActivity.class);
intent.putExtra("parcel_data", task);
startActivity(intent);
}
});
/*#######################################################*/
// import font
Typeface MLight = Typeface.createFromAsset(getAssets(), "fonts/ML.ttf");
Typeface MMedium = Typeface.createFromAsset(getAssets(), "fonts/MM.ttf");
// customize font
title_page.setTypeface(MMedium);
add_title.setTypeface(MLight);
title_task.setTypeface(MMedium);
add_desc.setTypeface(MLight);
desc_task.setTypeface(MMedium);
add_date.setTypeface(MLight);
date_task.setTypeface(MMedium);
add_prio.setTypeface(MLight);
prio_task.setTypeface(MMedium);
add_diff.setTypeface(MLight);
diff_task.setTypeface(MMedium);
btn_save.setTypeface(MMedium);
btn_cancel.setTypeface(MLight);
}
}
Это целевая активность:
public class MainActivity extends AppCompatActivity {
TextView title_page, sub_title_page, end_page;
Button buttonNewTask;
// 1- Declare RecyclerView
RecyclerView ourtasks;
// 2- Declare arrayList of tasks & Adapter
ArrayList<myTasks> taskList;
tasksAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
title_page = findViewById(R.id.title_page);
sub_title_page = findViewById(R.id.sub_title_page);
end_page = findViewById(R.id.end_page);
buttonNewTask = findViewById(R.id.buttonNewTask);
// import font
Typeface MLight = Typeface.createFromAsset(getAssets(), "fonts/ML.ttf");
Typeface MMedium = Typeface.createFromAsset(getAssets(), "fonts/MM.ttf");
// customize font
title_page.setTypeface(MMedium);
sub_title_page.setTypeface(MLight);
end_page.setTypeface(MLight);
//button font
buttonNewTask.setTypeface(MLight);
buttonNewTask.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//start a task add activity when button pressed
Intent a = new Intent(MainActivity.this,taskAdd.class);
startActivity(a);
}
});
//working with data
ourtasks = findViewById(R.id.ourtasks);
ourtasks.setLayoutManager(new LinearLayoutManager(this));
taskList = new ArrayList<myTasks>();
myTasks task = (myTasks) getIntent().getParcelableExtra("parcel_data");
taskList.add(task);
Log.i("TAG","===========================" + " " +task.getPrio_task());
adapter = new tasksAdapter(MainActivity.this,taskList);
ourtasks.setAdapter(adapter);
}
}
трассировка стека logcat
2020-04-11 13:14:50.259 24573-24573/? I/art: Late-enabling -Xcheck:jni
2020-04-11 13:14:50.259 24573-24573/? I/art: Reinit property: dalvik.vm.checkjni= false
2020-04-11 13:14:50.303 24573-24580/? E/art: Failed sending reply to debugger: Broken pipe
2020-04-11 13:14:50.304 24573-24580/? I/art: Debugger is no longer active
2020-04-11 13:14:50.304 24573-24580/? I/art: Starting a blocking GC Instrumentation
2020-04-11 13:14:50.375 24573-24573/? W/System: ClassLoader referenced unknown path: /data/app/comt.example.farida.taskand-2/lib/arm64
2020-04-11 13:14:50.376 24573-24573/? W/art: JIT profile information will not be recorded: profile file does not exits.
2020-04-11 13:14:50.384 24573-24573/? I/InstantRun: starting instant run server: is main process
2020-04-11 13:14:50.397 24573-24573/? I/HwCust: Constructor found for class android.app.HwCustActivityImpl
2020-04-11 13:14:50.410 24573-24573/? I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
2020-04-11 13:14:50.421 24573-24573/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
2020-04-11 13:14:50.438 24573-24573/? I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
2020-04-11 13:14:50.438 24573-24573/? I/art: at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void comt.example.farida.taskand.SplashScreen.onCreate(android.os.Bundle) (SplashScreen.java:13)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6912)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1123)
2020-04-11 13:14:50.438 24573-24573/? I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2746)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2864)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1567)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.os.Looper.loop() (Looper.java:156)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6520)
2020-04-11 13:14:50.438 24573-24573/? I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:941)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:831)
2020-04-11 13:14:50.438 24573-24573/? I/art: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/comt.example.farida.taskand-2/base.apk", zip file "/data/app/comt.example.farida.taskand-2/split_lib_dependencies_apk.apk", zip file "/data/app/comt.example.farida.taskand-2/split_lib_slice_0_apk.apk", zip file "/data/app/comt.example.farida.taskand-2/split_lib_slice_1_apk.apk", zip file "/data/app/comt.example.farida.taskand-2/split_lib_slice_2_apk.apk", zip file "/data/app/comt.example.farida.taskand-2/split_lib_slice_3_apk.apk", zip file "/data/app/comt.example.farida.taskand-2/split_lib_slice_4_apk.apk", zip file "/data/app/comt.example.farida.taskand-2/split_lib_slice_5_apk.apk", zip file "/data/app/comt.example.farida.taskand-2/split_lib_slice_6_apk.apk", zip file "/data/app/comt.example.farida.taskand-2/split_lib_slice_7_apk.apk", zip file "/data/app/comt.example.farida.taskand-2/split_lib_slice_8_apk.apk", zip file "/data/app/comt.example.farida.task
2020-04-11 13:14:50.438 24573-24573/? I/art: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
2020-04-11 13:14:50.438 24573-24573/? I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
2020-04-11 13:14:50.438 24573-24573/? I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
2020-04-11 13:14:50.438 24573-24573/? I/art: at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void comt.example.farida.taskand.SplashScreen.onCreate(android.os.Bundle) (SplashScreen.java:13)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6912)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1123)
2020-04-11 13:14:50.438 24573-24573/? I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2746)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2864)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1567)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.os.Looper.loop() (Looper.java:156)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6520)
2020-04-11 13:14:50.438 24573-24573/? I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:941)
2020-04-11 13:14:50.438 24573-24573/? I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:831)
2020-04-11 13:14:50.445 24573-24573/? I/BitmapFactory: set decoder allocator to gralloc
2020-04-11 13:14:50.446 24573-24573/? I/gralloc: alloc_device_alloc:564: Alloc handle(0x7d51484900): interfmt=1, stride=1024, size=2457600, usage=0x2000003
2020-04-11 13:14:50.457 24573-24573/? I/gralloc: alloc_device_alloc:564: Alloc handle(0x7d4191b000): interfmt=1, stride=3008, size=21659648, usage=0x2000003
2020-04-11 13:14:50.520 24573-24573/? I/gralloc: alloc_device_free:586: Free handle(0x7d4191b000)
2020-04-11 13:14:50.520 24573-24573/? I/gralloc: alloc_device_free:586: Free handle(0x7d51484900)
2020-04-11 13:14:50.533 24573-24573/? I/HwSecImmHelper: mSecurityInputMethodService is null
2020-04-11 13:14:50.536 24573-24573/? I/HwPointEventFilter: support AFT
2020-04-11 13:14:50.573 24573-24595/? I/OpenGLRenderer: Initialized EGL, version 1.4
2020-04-11 13:14:50.577 24573-24595/? W/linker: /vendor/lib64/libhwuibp.so: unused DT entry: type 0xf arg 0xe3a
2020-04-11 13:14:54.609 24573-24573/comt.example.farida.taskand I/Process: Sending signal. PID: 24573 SIG: 9