+ @Override
+ public void onAddDomain(AppCompatDialogFragment dialogFragment) {
+ // Reapply the domain settings on returning to `MainWebViewActivity`.
+ reapplyDomainSettingsOnRestart = true;
+ currentDomainName = "";
+
+ // Get the new domain name `String` from `dialogFragment`.
+ EditText domainNameEditText = dialogFragment.getDialog().findViewById(R.id.domain_name_edittext);
+ String domainNameString = domainNameEditText.getText().toString();
+
+ // Initialize the database handler. `this` specifies the context. The two `nulls` do not specify the database name or a `CursorFactory`.
+ // The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
+ DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(this, null, null, 0);
+
+ // Create the domain and store the database ID in `currentDomainDatabaseId`.
+ int newDomainDatabaseId = domainsDatabaseHelper.addDomain(domainNameString);
+
+ // Create an intent to launch the domains activity.
+ Intent domainsIntent = new Intent(this, DomainsActivity.class);
+
+ // Put extra information instructing the domains activity to directly load the current domain.
+ domainsIntent.putExtra("LoadDomain", newDomainDatabaseId);
+
+ // Make it so.
+ startActivity(domainsIntent);
+ }
+