Reputation: 11
So I was working with a Viewpager in which I had 3 fragments. One fragment was made for sending messages but I had a problem with that because it closed right after I clicked the button to send the message.
The message was sent and the Database was updated but the fragment closed everytime and sent me to the first fragment I had in my viewpager.
So what I did next was delete the Message Fragment from my Viewpager and put a button that took me to an activity whose whole purpose was to send messages.
The problem is that even though everything is working fine the activity also closes after sending the message and takes me to my Activity that has the viewpager.
I deleted that fragment from my Viewpager and tried putting that in an activity to see if the problem was with the fragment because I've never really worked with fragments.
My "Chat Activity"
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
title = preferences.getString("Titulo", "Sin titulo");
setContentView(R.layout.activity_chat_grupo);
mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Chat");
mToolbar.setTitleTextColor(Color.WHITE);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mAuth = FirebaseAuth.getInstance();
mCurrent_user_id = mAuth.getCurrentUser().getDisplayName();
mPics = FirebaseDatabase.getInstance().getReference().child("Users").child(mCurrent_user_id).child("imagen");
messages = findViewById(R.id.list_of_messages);
input = (EditText) findViewById(R.id.input);
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar c = Calendar.getInstance();
SimpleDateFormat fecha = new SimpleDateFormat("dd-MM (HH:mm:ss)");
final String fecha_d = fecha.format(c.getTime());
mPics.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
url = dataSnapshot.getValue().toString();
Log.d("PHOTOURL", url);
FirebaseDatabase.getInstance().getReference().child("grupos").child(title).child("chat")
.push()
.setValue(new ChatGrupoAdapter(input.getText().toString(),
mCurrent_user_id, fecha_d, url)).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
input.setText("");
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
});
adapter = new FirebaseListAdapter<ChatGrupoAdapter>(ChatGrupo.this, ChatGrupoAdapter.class,
R.layout.message, FirebaseDatabase.getInstance().getReference().child("grupos").child(title).child("chat")) {
@Override
protected void populateView(View v, ChatGrupoAdapter model, int position) {
TextView messageText = (TextView) v.findViewById(R.id.message_text);
TextView messageUser = (TextView) v.findViewById(R.id.message_user);
TextView messageTime = (TextView) v.findViewById(R.id.message_time);
CircleImageView messageUserpic = v.findViewById(R.id.user_image);
messageText.setText(model.getMensaje());
messageUser.setText(model.getUsuario());
Picasso.get().load(model.getUserphoto()).into(messageUserpic);
messageTime.setText(model.getMessageTime());
}
};
messages.setAdapter(adapter);
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
//logcat after showing the new message in the listview.
05-15 20:39:24.418 26610-26610/com.example.danny.trendy_reads D/Picasso: Main created [R51] Request{https://firebasestorage.googleapis.com/v0/b/trendyreads-658db.appspot.com/o/Imagenes%2Fvanessa.jpg%2Fcropped3415433131357908162.jpg?alt=media&token}
05-15 20:39:24.427 26610-26610/com.example.danny.trendy_reads D/Picasso: Main completed [R51] from MEMORY
05-15 20:39:24.429 26610-26610/com.example.danny.trendy_reads W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
endBatchEdit on inactive InputConnection
05-15 20:39:24.430 26610-26610/com.example.danny.trendy_reads W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
endBatchEdit on inactive InputConnection
05-15 20:39:24.483 26610-26610/com.example.danny.trendy_reads W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
05-15 20:39:24.540 26610-26610/com.example.danny.trendy_reads W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
05-15 20:39:24.546 26610-26610/com.example.danny.trendy_reads W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
05-15 20:39:24.572 26610-26610/com.example.danny.trendy_reads W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
endBatchEdit on inactive InputConnection
05-15 20:39:29.186 26610-26696/com.example.danny.trendy_reads V/FA: Inactivity, disconnecting from the service
05-15 20:39:46.519 26610-28425/com.example.danny.trendy_reads E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE)
05-15 20:39:46.519 26610-28425/com.example.danny.trendy_reads I/chatty: uid=10158(com.example.danny.trendy_reads) Binder:26610_5 identical 3 lines
05-15 20:39:46.519 26610-28425/com.example.danny.trendy_reads E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE)
Upvotes: 0
Views: 182
Reputation: 11
After trying absolutely everything, I found that adding "android:launchMode="singleInstance" solved my problem. (In Manifest)
I also changed the List to a RecyclerView which didn't do anything for me. I have another activity that has the same exact methods and this doesn't happen, anyway that's the answer.
Upvotes: 1
Reputation: 6063
JVMTI is the debugging and profiling protocol. So, I'm guessing it's something peculiar to the environment you are attempting to run your application in.
try to do File ---> Invalidate Caches / Restart , it may help you.
Upvotes: 0