Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Development -- AlertDialog showing inside of Tab Activity
    primarykey
    data
    text
    <p>I'm having trouble getting an alert dialog to show inside of a Tab Activity. My app will force close every time I try and get the alert dialog to show. My code is as follows:</p> <pre><code>public class TablesActivity extends ListActivity { final int INFO_ID = 0; final int STATUS_ID = 1; AlertDialog alert = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure you want to mark table as dirty?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(getApplicationContext(), "Table Marked Dirty", Toast.LENGTH_LONG).show(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); alert = builder.create(); setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.history, TABLES)); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_LONG).show(); } }); lv.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { alert.show(); // TODO Auto-generated method stub return true; } }); } static final String[] TABLES = new String[] { "Table 1", "Table 2", "Table 3", "Table 4", "Table 5", "Table 6", "Table 7", "Table 8", "Table 9", "Table 10", "Table 11", "Table 12", "Table 13" }; } </code></pre> <p>The problem is arising when I attempt to perform the dialog.show(), and nowhere else. I am getting the logcat error of:</p> <p>04-16 17:25:15.519: ERROR/AndroidRuntime(311): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@44f08320 is not valid; is your activity running?</p> <p>The error is originating from the dialog.show() line. I am not sure what exactly to do here. The activity is running, after being started earlier by an ActivityGroup spawned by the TabHost.</p> <p>Any ideas on what I can do to fix this problem? I'm at my wits end.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload