Click here to Skip to main content
15,846,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a program which is used to add the data to the firestore. On successful operation the current activity will redirect to another activity showing successful message. But if the operation fail or the internet is down for more than 10 seconds it should go to another activity showing error message. But the above program keep on waiting for the internet and doesn't redirect to error message. So is there any way that I can show redirect to error page if there's no internet or some other error occur. Here's my code:

What I have tried:

Toast.makeText(getBaseContext(),"Please wait while your submission is being sent",Toast.LENGTH_LONG).show();
mfirestore.collection("MYPrince").add(usmap).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
        @Override
        public void onSuccess(DocumentReference documentReference) {
            Intent i = new Intent(Thanks.this, success.class);
            startActivity(i);
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Intent i = new Intent(Thanks.this, error.class);
            startActivity(i);
        }
    });
Posted
Comments
David Crow 24-Aug-18 21:21pm    
Why are you creating activities just to show a success/failure message? That's a bit too much overhead. A 2-3 line AlertDialog is more than enough.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900