Navigation Drawer hangs while opening/closing on some devices

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago


While working with my android app, I found out that navigation drawer hangs while opening as well as closing. It hangs for 2-3 seconds. On most devices, it's fine (mostly with Stock Android) but on some devices, it hangs (Mostly Samsung).

Home.java (activity in which drawer is implemented):

public class Home extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener{

    Fragment fragment;

    public void MsgBox(String title, String msg,int id){
        new LovelyInfoDialog(this)
                .setTopColorRes(R.color.primary)
                .setIcon(R.drawable.ic_info_white_24dp)
                //This will add Don't show again checkbox to the dialog. You can pass any ID as argument
                .setNotShowAgainOptionEnabled(id)
                .setTitle(title)
                .setMessage(msg)
                .show();
    }

    public boolean showAds() {
        SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        boolean showAd = getPrefs.getBoolean("showAd", true);
        return showAd;
    }

    public static boolean hasPermissions(Context context, String... permissions) {
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
            for (String permission : permissions) {
                if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
                    return false;
                }
            }
        }
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        hasPermissions(this,Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.GET_ACCOUNTS);
        
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago

I solved the problem by decreasing the image resolution of Navigation Drawer header image. It was 1600*1200 and I changed the resolution to 400*300. After doing this, the drawer opens smoothly on affected phones.

It wasn't my coding fault but it might be a problem with customized ROMs how they handle the images with high resolution because the drawer was already opening smoothly on Stock Android.

 

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community