1

*Am working on an App where i have used an old navigation drawer pattern.My problem is when am pressing the back button,navigation drawer is coming out instead of the previous activity.I think am not closing the navigation drawer and i really don't know how to close the navigation drawer. So,please help me to get out of this.Thank You

         public class ReportProblem extends Activity {

    WebView mWebView;

 SimpleSideDrawer rightSlider;
LinearLayout ll_menu, ll_start_stop;
Context mContext = this;

private RelativeLayout rl_main;

private LoaderProgress loader;
Utillity utillity;

 private ImageView iv_browser;

 private CustomText tv_open_in_browser;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_report_problem);

utillity =  new Utillity(mContext);

ll_menu = (LinearLayout) findViewById(R.id.ll_menu);

rightSlider = new SimpleSideDrawer(this);

rightSlider.setLeftBehindContentView(R.layout.menu_drawer);

rl_main = (RelativeLayout) findViewById(R.id.rl_main);

  menuClick();
  ll_menu.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        rightSlider.toggleLeftDrawer();

    }
});

rl_main.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }
});

loader = new LoaderProgress(mContext);

mWebView = (WebView) findViewById(R.id.web_activity_summery);
mWebView.getSettings().setJavaScriptEnabled(true);


iv_browser=(ImageView)findViewById(R.id.iv_browser);

tv_open_in_browser=(CustomText)findViewById(R.id.tv_open_in_browser);

iv_browser.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if(v.getTag().toString().equals("0"))
        {
            v.setTag("1");
            tv_open_in_browser.setVisibility(View.VISIBLE);
        }
        else
        {
            v.setTag("0");
            tv_open_in_browser.setVisibility(View.GONE);
        }
    }
});


tv_open_in_browser.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

        String base64 = Base64.encodeToString(ParseUser.getCurrentUser()
                .getObjectId().toString().getBytes(), Base64.DEFAULT);

            Intent browserIntent = new Intent(Intent.ACTION_VIEW);
                browserIntent.setData(Uri.parse("http://.com/app/feedback/index.html?id="+URLEncoder.encode(base64)));
            startActivity(browserIntent);
            v.setTag("0");
            tv_open_in_browser.setVisibility(View.GONE);
    }
});


mWebView.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

        if(iv_browser.getTag().toString().equals("1"))
        {
            iv_browser.setTag("0");

            tv_open_in_browser.setVisibility(View.GONE);
        }

    }
});







if (utillity.isNetworkAvailable()) {

    String base64 = Base64.encodeToString(ParseUser.getCurrentUser()
            .getObjectId().toString().getBytes(), Base64.DEFAULT);
    mWebView.loadUrl("http://com/app/feedback/index.html?   id="+URLEncoder.encode(base64));

} else {

    showAlertDialog("Please make sure that you have an active Internet connection");
}

new GpsSharedPrefrence(mContext)
        .setActivityState(GpsSharedPrefrence.ActivityResume);

  }



  @Override
  protected void onResume() {
   // TODO Auto-generated method stub

   new GpsSharedPrefrence(mContext)
        .setActivityState(GpsSharedPrefrence.ActivityResume);

      super.onResume();
}

  @Override
 protected void onPause() {
new GpsSharedPrefrence(mContext)
        .setActivityState(GpsSharedPrefrence.ActivityPause);
super.onPause();
}

public void menuClick() {

View menuView = rightSlider.getLeftBehindView();

   LinearLayout ll_activity, ll_history, ll_configure_device, ll_settings,  ll_activity_summery, ll_logout;

 ll_activity = (LinearLayout) menuView.findViewById(R.id.ll_activity);
 ll_history = (LinearLayout) menuView.findViewById(R.id.ll_history);
 ll_configure_device = (LinearLayout) menuView
        .findViewById(R.id.ll_configure_device);
 ll_settings = (LinearLayout) menuView.findViewById(R.id.ll_settings);
 ll_activity_summery = (LinearLayout) menuView
        .findViewById(R.id.ll_activity_summery);
ll_logout = (LinearLayout) menuView.findViewById(R.id.ll_logout);
LinearLayout ll_report_problem = (LinearLayout)  menuView.findViewById(R.id.ll_report_problem);
     ll_report_problem.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {

        rightSlider.toggleLeftDrawer();

        // Intent intentActivity = new Intent(mContext,
        // Activities.class);
        // startActivity(intentActivity);
        // finish();
    }
});
LinearLayout ll_treadmill = (LinearLayout)    menuView.findViewById(R.id.ll_treadmill);


 ll_treadmill.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {


        Intent intentActivity = new Intent(mContext,
                TreadMillActivity.class);
        Bundle  animation=ActivityOptions.makeCustomAnimation(getApplicationContext(), 
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);


    }
});

ll_activity.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {

        Intent intentActivity = new Intent(mContext, Activities.class);
        Bundle animation=ActivityOptions.makeCustomAnimation(getApplicationContext(),
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);

    }
});
ll_history.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intentActivity = new Intent(mContext,
                HistoryActivity_web.class);
        Bundle animation=ActivityOptions.makeCustomAnimation(getApplicationContext(), 
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);

    }
});
ll_configure_device.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intentActivity = new Intent(mContext,
                InsoleConnection.class);
        Bundle  animation=ActivityOptions.makeCustomAnimation(getApplicationContext(),
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);

    }
});
ll_settings.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intentActivity = new Intent(mContext,
                SettingsActivity.class);
        Bundle animation=ActivityOptions.makeCustomAnimation(getApplicationContext(),
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);

    }
});

ll_activity_summery.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intentActivity = new Intent(mContext,
                ActivitySummery.class);
        Bundle animation=ActivityOptions.makeCustomAnimation(getApplicationContext(),
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);

      }
   });

    ll_logout.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {

        new UserSharedPrefrence(mContext).clearPrefrence();
        new BleSharedPrefrence(mContext).clearPrefrence();
        finish();
    }
   });

  }

 public void showAlertDialog(String Message) {
final Dialog dialog = new Dialog(mContext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(
        new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setCancelable(false);
dialog.setContentView(R.layout.cart_dialog);

TextView txtdetail = (TextView) dialog.findViewById(R.id.txtdetail);
TextView txtno = (TextView) dialog.findViewById(R.id.txtno);

txtno.setVisibility(View.GONE);

TextView txtyes = (TextView) dialog.findViewById(R.id.txtyes);

txtyes.setText("Ok");

txtdetail.setText(Message);
txtyes.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        dialog.dismiss();
    }
});
dialog.show();
}

 @Override
 public void onBackPressed() {
 if(rightSlider.isDrawerOpen(GravityCompat.START)){
    rightSlider.closeDrawer(GravityCompat.START);
  }
   else{

 super.onBackPressed();

   }

 }
Prashant Gaurav
  • 325
  • 3
  • 9

1 Answers1

0

Have you implemented ActionBarDrawerToggle for NavDrawer? You can assign it to your NavDrawer and set it to syncState()

mBaseDrawerLayout.setDrawerListener(mBaseDrawerToggle);
mBaseDrawerToggle.syncState();

Follow this up: Creating a Navigation Drawer And below code to close NavDrawer when going to another activity:

mBaseDrawerLayout.closeDrawer(mBaseDrawerList);
mBaseDrawerToggle.syncState();
kevoroid
  • 5,052
  • 5
  • 34
  • 43
  • Am not using the fragment ,navigation drawer is having separate code for every activity. – Prashant Gaurav Feb 19 '16 at 07:48
  • its fine. this code (way of dealing with NavDrawer) is on dependent on Fragments or anything. All you need to do is to handle closing state when user navigates to another activity (via Intent) or touches the NavDrawer toggle on ActionBar. – kevoroid Feb 19 '16 at 07:55
  • So i have to close the drawer where we are using intent to call our next activity next activity. – Prashant Gaurav Feb 19 '16 at 08:51
  • Yes. you call "closeDrawer" and sync the DrawerToggle state. – kevoroid Feb 19 '16 at 09:07