Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
I have main_activity and dashboard_activity, on dashboard_activity I added fragment using code in OnBackPressed() method


C#
public override  void OnBackPressed()
    {
         //base.OnBackPressed();
             FragmentTransaction transaction =FragmentManager.BeginTransaction();
             Dialog dialog = new Dialog();
             dialog.Show(transaction,"dialog_fragment");
    }


Quote:
Note:My code for btnExitapp work fine only once after deployment and if I reopen the app in emulator and press btnExit it close app and reopen with Dashboard_Activity instead of closing app.

Please guide me to achieve that when BtnLogout pressed, should go back to Main_Activity as it work on backpress button and when BtnExitapp pressed should close the app


What I have tried:

Quote:
My fragment code is here

C#
<blockquote class="quote"><div class="op">Quote:</div>class Dialog:DialogFragment
{
    private Button btnExitapp;
    private Button btnLogOut;

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
         base.OnCreateView(inflater, container, savedInstanceState);
        var view = inflater.Inflate(Resource.Layout.dialog, container,false);

        btnExitapp=view.FindViewById(Resource.Id.btnExitapp);
        btnExitapp.Click += BtnExitapp_Click;

        btnLogOut = view.FindViewById(Resource.Id.btnLogOut);
        btnLogOut.Click += BtnLogOut_Click;

        return view;
    }
    
    private void BtnLogOut1_Click(object sender, EventArgs e)
    {
        
        
    }

    private void BtnExitapp1_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.GetCurrentProcess().Kill();
    }
    
}</blockquote>
Posted
Updated 14-Apr-22 22:22pm

1 solution

At first, if you want to go back to the previous activity in your dialogframent, you can try to call the base.OnBackPressed(); in the private void BtnLogOut1_Click(object sender, EventArgs e). In addition, maybe you need to call it twice, from dialog to dashboard activity and then the main activity.

Then if you want to exit the app, you can use the following code:

private void BtnExitapp1_Click(object sender, EventArgs e)
{
   Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
}
 
Share this answer
 

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