0

i got error when use put Extra

    @Override
    public void onUserClicked(User user) {
    Intent intent = new Intent(getApplicationContext(), ChatActivity.class);
    intent.putExtra(Constans.KEY_USER, user);
    startActivity(intent);
    finish();

this is the Constans file

package com.example.talkmore.utilities;

public class Constans {
public static final String KEY_COLLECTION_USERS = "users";
public static final String KEY_NAME = "name";
public static final String KEY_EMAIL = "email";
public static final String KEY_PASSWORD = "password";
public static final String KEY_PREFERENCE_NAME = "chatAppPreference";
public static final String KEY_IS_SIGNED_IN = "isSignedIn";
public static final String KEY_USER_ID = "userId";
public static final String KEY_IMAGE = "image";
public static final String KEY_FCM_TOKEN = "fcmtoken";
public static final String KEY_USER = "user"; }

Can anyone help me to solve the problem. Thankyou

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
  • 1
    putExtra has many different signatures, but there is not one which takes User as a 2nd argument. You could make User implement Serializiable and it'll work because then it'll match [this signature](https://developer.android.com/reference/android/content/Intent#putExtra(java.lang.String,%20java.io.Serializable)) – Michael Oct 07 '21 at 12:47
  • @Michael how can i use User implement Serializiable in my code ? – Rachmat Rizqi Kurniawan Oct 08 '21 at 01:27
  • What do you mean by "Cannot resolve method 'putExtra(java.lang.String, com.example.talkmore.models.User)'"? Is it highlighted in red? Or? Please respond with @AlexMamo – Alex Mamo Oct 08 '21 at 08:31
  • @RachmatRizqiKurniawan To answer your question to Michael, you can directly have your user object implement Serializable like this `public class User implements Serializable` You can also refer to a similar question here https://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents – Zerosero Oct 25 '21 at 12:02

0 Answers0