8

I'm fairly new to Android development and I've created my first "real" application that does the following:

  • Launches MainActivity
  • MainActivity processes Extra Data and then displays a ViewDialog that extends Dialog. ViewDialog has a showDialog() method that does the following to setup and display the Dialog:

    protected void showDialog(final Activity activity)
    {
        dialog = new Dialog(activity);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(false);
        dialog.setContentView(dialog_layout);
    
        // Set background color of the dialog
        ConstraintLayout currentLayout = (ConstraintLayout) dialog.findViewById(R.id.Dialog);
    
        // setup of views etc ...
    
        // Finally dislay `Dialog`
        dialog.show();
    
        // Method called to start a `DialogTimer` which extends `CountDownTimer`
    }
    
  • MainActivity shows the ViewDialog as follows:

     public class MainActivity extends AppCompatActivity {
         private static Context appContext;
         private static ViewDialog notify;
    
         protected void onCreate(Bundle savedInstanceState) {
    
             // methods and processing etc...        
    
             // time to display dialog 
             notify = new ViewDialog(mParameters, mThemeHandler );
    
             // ******************** Show dialog box *******************
             notify.showDialog(activity: this);   // showDialog just calls `Dialog.show()`
             notify.ApplyTheme();
         }
    
  • When the timer expires or the user presses a button the ViewDialog is closed and the application is finished with the following code:

        mButton1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CancelTimer();
            activity.finishAndRemoveTask();
            dialog.dismiss();
    

The problem is that when the ViewDialog is dismissed I can occasionally see what looks like a message that is displaying the activities android:label that is setup in the AndroidManifest file.

Video of what is happening

I'm not sure why this happens, but I assume it's displaying some item of the MainActivity layout when the ViewDialog closes that uses it's own dialog_layout layout file.

I've fiddled with so many different things and changed code/layouts etc and I haven't been able to find my error.

What are some pointers and hints that will help me fix this? I'm happy to provide more details if needed.

The layout and manifest files are here:

Chimera
  • 5,884
  • 7
  • 49
  • 81
  • 2
    When you say, “displaying a message” what exactly are you seeing? – flopshot Oct 05 '19 at 23:27
  • 2
    Can you post any screenshot of the message you see after Dialog is dismissed? – Hamza Oct 05 '19 at 23:29
  • Also in your activity_main.xml file you have placed width and height of the main layout 0dp. Just make it mach_parent so that it can expand through all screen. – Hamza Oct 05 '19 at 23:34
  • @flopshot It looks like a toast sort of message only displaying the name of the app. It appears very briefly when the dialog is dismissed. – Chimera Oct 06 '19 at 04:54
  • @Hamza I can try to post a screen shot. But the little "toast" like message only appears for less than a second. It may be hard to capture it. – Chimera Oct 06 '19 at 04:56
  • What kind of device are you using? – flopshot Oct 06 '19 at 11:00
  • 1
    @flopshot phone and tablets running Android 5.1 and 9.0. BTW, I'm in Las Vegas also.... :-) – Chimera Oct 06 '19 at 13:00
  • 1
    go through this [Link](https://medium.com/@nhancv/android-show-dialog-without-activity-context-94661d48400f). hope you'll find something useful – Alfaizkhan Oct 08 '19 at 04:39
  • Minimal example Android Studio project provided. I will provide a large bounty for the person who solves this issue for me..... I'm so new to Android development and I've tried so many things... I'm at a loss now to know what to do next.... – Chimera Oct 09 '19 at 21:00

4 Answers4

3

You can achieve this by setting the android:theme attribute to @android:style/Theme.NoTitleBar on your element in your AndroidManifest.xml like this:

<activity android:name=".Activity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
Alfaizkhan
  • 289
  • 1
  • 9
2

The code you've posted is not enough to figure out why this is happening, but there is one universal solution not to see Activity title(that is is set in the label field of manifest).

Declare in your styles.xml a new theme like

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowContentOverlay">@null</item>
</style>

and after that make it to be the theme of your activity like this

 <activity
           ...
           android:name="boha.notify.MainActivity"
           android:theme="@style/AppTheme.NoActionBar">
           ...
</activity>

While I am not 100 percent sure(because this behavior can be altered in an actual code of your activity) I think it might help.

I hope it will help.

Pavlo Ostasha
  • 14,527
  • 11
  • 35
  • Thank you Paul. I will give it a try. – Chimera Oct 07 '19 at 13:27
  • Paul, I tried that and it didn't work. I did notice that when I set the activity's title, in code using `setTitle()` to a very long string I could see very clearly that the little "toast" like message showing when the dialog closes is the main activity's title. I will link to a video showing what is happening soon. – Chimera Oct 07 '19 at 16:38
  • Paul, also what else of my code do you need to see? I can't show all the code. Perhaps I'll create an [mcve] to post. – Chimera Oct 07 '19 at 17:06
2
notify.setOnDissmissListener({CancelTimer()
    activity.finishAndRemoveTask()
    dialog.dismiss()})
Shahriyar Aghajani
  • 431
  • 1
  • 6
  • 22
2

It turns out that if I change:

public class MainActivity extends AppCompatActivity {

to

public class MainActivity extends Activity {

the problem goes away. I don't know why, but I'll take it.

Chimera
  • 5,884
  • 7
  • 49
  • 81