Open rohankeskar19 opened 5 years ago
@rohankeskar19 Whole point working with sockets.io client in java is that library returns data in own thread, meaning not on main/ui thread. So if you want to update your views, you should send your data to UI thread. Simply you can do it with textview.post(()- > { textView.setText(dataFromSocket); });
`package com.example.chatapplication;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; import androidx.core.content.ContextCompat;
import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.os.StrictMode; import android.text.Editable; import android.text.TextWatcher; import android.util.Base64; import android.util.Log; import android.view.View; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView;
import com.bumptech.glide.Glide; import com.example.chatapplication.Models.Freind; import com.example.chatapplication.Models.User; import com.github.nkzawa.emitter.Emitter; import com.github.nkzawa.socketio.client.IO; import com.github.nkzawa.socketio.client.Socket; import com.vanniktech.emoji.EmojiManager; import com.vanniktech.emoji.EmojiPopup; import com.vanniktech.emoji.EmojiProvider; import com.vanniktech.emoji.ios.IosEmojiProvider;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException; import java.util.Timer; import java.util.TimerTask;
import static android.app.UiModeManager.MODE_NIGHT_AUTO;
public class ChatActivity extends AppCompatActivity {
}
`
When i try to change the text based on events like typing or stopped typing, or wentOffline or came online
This is giving me an error like
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.