Reputation: 567
I've made this simple dialog fragment to display over the home screen, which works fine except when I dismiss the fragment dialog, a second little box appears with the word Dialogue in it. I can't for the life of me figure where its coming from.
Anyone have any suggestions? Could it be something to do with the chain of classes being called and that one of them is launching the alert again but without the custom layout view?
The dialog fragment.
public class DialogFragmentTest extends DialogFragment implements View.OnClickListener{
private AlertDialog.Builder mBuilder;
private AlertDialog mAlertDialog;
private View mDialogView;
private Button mOkBtn, mCancelBtn;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mDialogView = inflater.inflate(R.layout.dialog_layout, container, false);
Log.d("DialogFrag", "onCreate");
// mBuilder = new AlertDialog.Builder(getContext());
mOkBtn = (Button) mDialogView.findViewById(R.id.ok);
mCancelBtn = (Button) mDialogView.findViewById(R.id.cancel);
mOkBtn.setOnClickListener(this);
mCancelBtn.setOnClickListener(this);
return mDialogView;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.ok:
this.dismiss();
break;
case R.id.cancel:
this.dismiss();
break;
}
}
}
Dialog Receiver class.
public class AlertDialogReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent alarmIntent = new Intent("android.intent.action.MAIN");
alarmIntent.setClass(context, AlarmDialogClass.class);
alarmIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(alarmIntent);
}
}
The class that instantiates the fragment.
public class AlarmDialogClass extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("AlarmClass", "onCreate:");
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
DialogFragmentTest dft = new DialogFragmentTest();
dft.show(fm, "Sample Fragment");
}
}
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.android.shnellers.dialogue"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".AlarmDialogClass"
android:theme="@android:style/Theme.Dialog"
android:launchMode="singleInstance" />
<receiver android:process=":remote" android:name=".AlertDialogReceiver"/>
</application>
Upvotes: 1
Views: 458
Reputation: 39191
It's the AlarmDialogClass
Activity
. Even though you don't call setContentView()
, its window is still created, and with the Theme.Dialog
, that's what it'll look like.
Finishing the Activity
as soon as the DialogFragment
is dismissed would take care of it, though that's a little unwieldy, and you might still see the Activity
for a split second before it goes. You could instead use a NoDisplay
theme for the Activity
, but you'd still have to handle finishing the Activity
after the DialogFragment
is dismissed.
It's probably easier to just use the Activity
itself as your dialog, and drop the DialogFragment
.
Upvotes: 1