2

I am new to android and i am stuck with this. I have a login activity, when i click on login it goes to main menu where i have a grid view, so when i select an item from grid view it goes to next activity say "B",and when i click on confirm button in activity "B" it shows me activity "c" which has home button. I am using android:theme="@android:style/Theme.Dialog" theme which is showing my activity as a dialog.

When Clicked on home button, it should bring me to the main menu i.e. the Gridview. So now when i press back button in main menu it shows me activity "c", but my problem is i have to go to Login Activity.

I have tried putting finish() in activity "B" but in activity "C" when i click back button i want to c activity "B" which currently showing me main menu i.e. the gridview. I have also tried setting intent flag Intent.FLAG_ACTIVITY_CLEAR_TOP in activity "c" but it shows a black screen for a second before showing main menu.

2 Answers2

0

When you click on your "home" button, you need to go back to the grid view activity like this:

Intent intent = new Intent(this, MainMenuActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);

This will clear all activities in the task, back to (but excluding) the main menu activity. It will then call onNewIntent() on the existing instance of your main menu activity, followed by onResume().

This should solve your "black screen" problem.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
0

Guys The Simple Solution is

Step 1) Create a drawable shape with the color you want like this

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/white" />
</shape>

Step 2) add this to your theme in style.xml

 <itemname="android:windowBackground">@drawable/any_default_background</item>

Actually the window color is by default black in dark mode in android so you can change the color to the activity screen background color and the black color by default would be gone.

you can try other solutions as well but this is the one i always use.