Search code examples
androidandroid-activity

While i am switching between activities my Application is blinking and showing previous activity in background


We have HomeActivity which is NavigationDrawyer Activity where there are many options like jobs and policies.if he clicks on jobs for the first time we will show JobUserForm.class and from next time onwards we will show JobsList.class if he clicks JobsList then JobDetails. the same way follows for Policies too.the problem is while i am navigating between these pages,the previous page is blinking in background for few seconds.for example if i click jobs in homeActivity while loading jobsList screen homeActivity screen is blinking in background.in the same way while loading jobDetails screen jobsList screen is blinking. it is happening same for policies too. how can i solve it.help me with a solution.

In my HomeActiivty.class

    @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {

            menuItem.setChecked(true);
            // close drawer when item is tapped
            switch (menuItem.getItemId()) {

                case R.id.nav_item_jobs:
                    if (internetConnection.checkConnection()) {
                        govJobs();
                    } else {
                        Toast.makeText(HomeActivity.this, "No internet connection", Toast.LENGTH_LONG).show();
                    }
                    break;
                case R.id.nav_item_policies:
                    if (internetConnection.checkConnection()) {
                        govPolicies();
                    } else {
                        Toast.makeText(HomeActivity.this, "No internet connection", Toast.LENGTH_LONG).show();
                    }
                    break;
                case R.id.nav_item_my_servant:
                    Toast.makeText(HomeActivity.this, "Coming soon", Toast.LENGTH_LONG).show();

                    break;

            }
            drawer.closeDrawers();
            return true;
        }



 private void govJobs() {
        job_rows_count = myAppDataBase.myDao().getNumberOfJobRows();
        if (job_rows_count >= 1) {
           // getWindow().setExitTransition(null);
            Intent intent = new Intent(HomeActivity.this, JobsList.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {
           //
            Intent intent =new Intent(HomeActivity.this, JobUserForm.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    }

    private void govPolicies() {

        policy_row_count = myAppDataBase.myDao().getNumberOfPolicyRows();

        if (policy_row_count >= 1) {
            Intent intent = new Intent(HomeActivity.this, PoliciesGrid.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {

            Intent intent = new Intent(HomeActivity.this, PolicyUserForm.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    }

Solution

  • You need to use overridePendingTransition(0,0); after startactivity() to remove any transitions that are to be used while switching activities.