Search code examples
androidandroid-layoutandroid-studioandroid-intentintentfilter

Error on Intent Activity in android studio. (Automatically change background)


Hello and good luck to everyone.

I am using Intent Activity in my project. And are having bugs with it. As follows: I have a list of the order of Activity:

A (Main) -> B (Login or SignUp) -> C (Menu) -> D (ListFoodOfMenu) -> E (DetailsFood)

From A-B-C-D or in many different order does not occur error.

But, since D-E has an error, the backgroud that I set for the xml layout disappears throughout the application, replacing it with the system color.

Who has a solution to help me and what to do to handle this error. Thank you.

This is a UI when there are no errors and then the UI is faulty:

UI is not faulty

UI is faulty

This is my code Intent:

A-B:

btnSignUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent moveToSignUp = new Intent(getApplicationContext(), SignUpActivity.class);
                startActivity(moveToSignUp);
                finishActivity(1);
            }
        });

        btnSignIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent moveToSignIn = new Intent(getApplicationContext(), SignInActivity.class);
                startActivity(moveToSignIn);
                finishActivity(1);
            }
        });

B-C:

Intent moveToHome = new Intent(getApplicationContext(), Home.class);
                                    Common.currentUser = user;
                                    startActivity(moveToHome);

C-D:

//Get CategoryID and send to new Activity:
                        Intent moveToFoodList = new Intent(getApplicationContext(), FoodListActivity.class);
                        //Because CategoryID is Key, so we just get key of this item:
                        moveToFoodList.putExtra("CategoryID", adapter.getRef(position).getKey());
                        startActivity(moveToFoodList);

D-E:

//Start Activity FoodDetails
                        Intent moveToFoodDetails = new Intent(getApplicationContext(), FoodDetailsActivity.class);
                        moveToFoodDetails.putExtra("FoodId", searchAdapter.getRef(position).getKey());
                        // Send FoodId to FoodDetailsActivity
                        moveToFoodDetails.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                        startActivity(moveToFoodDetails);

E-D (At this point the error has occurred):

btnCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new Database(getApplicationContext()).addToCart(new Order(
                        "", //Id tự tăng
                        Common.currentUser.getPhone(),
                        FoodId,
                        currentFood.getName(),
                        numberButton.getNumber(),
                        currentFood.getPrice(),
                        currentFood.getDiscount()
                ));
               finish();
        Toast.makeText(FoodDetailsActivity.this, "Added To Cart", Toast.LENGTH_SHORT).show();
                    }
                });

I have struggled with this error for months and still can not figure out how to fix it. We look forward to much help from Pro. Sincerely thank.


Solution

  • It is because you are having library 'com.cepheuen.elegant-number-button:lib:1.0.2' & that library also has background resource named background.xml which is being override with your background.jpg, when you reach FoodDetailsActivity screen.

    Solution : Rename your background.jpg to background_1.jpg.