{"id":2869,"date":"2014-03-02T01:05:40","date_gmt":"2014-03-02T01:05:40","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/02\/android-why-is-tabactivity-with-activitys-crashing-when-open-dialog-collection-of-common-programming-errors\/"},"modified":"2014-03-02T01:05:40","modified_gmt":"2014-03-02T01:05:40","slug":"android-why-is-tabactivity-with-activitys-crashing-when-open-dialog-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/02\/android-why-is-tabactivity-with-activitys-crashing-when-open-dialog-collection-of-common-programming-errors\/","title":{"rendered":"android why is TabActivity with Activity&#39;s crashing when open Dialog-Collection of common programming errors"},"content":{"rendered":"<p>I see there are like 10 answers for this question and i have read them all but cannot get this to work.<\/p>\n<p>Im moving my activity&#8217;s into this <code>TabGroup<\/code> and I have 3 activity&#8217;s inside a tabgroup and got help doing it from here: Multiple Android Activities in a TabActivity<\/p>\n<p>When opening a Custom Dialog i get this error:<\/p>\n<p>07-12 10:07:56.985: ERROR\/AndroidRuntime(9532): android.view.WindowManager$BadTokenException: Unable to add window &#8212; token android.app.LocalActivityManager$LocalActivityRecord@462d96f0 is not valid; is your activity running?<\/p>\n<p>I know this error say that Context is bad.<br \/>\nOn the <code>ColorPickerView<\/code> (belove) that dont work Im debugging and can see the Constructor doing it&#8217;s job but as soon as constructor finish it crashed.<\/p>\n<p>The think is i got 3 similar error from the other two activity&#8217;s, one CheckBox, and two Spinner&#8217;s.<br \/>\nI could easily fix it by changing the Context appropriately .<\/p>\n<p>This on is more complicated and the View stack looks like this<\/p>\n<p>TabGroup &#8230;&#8230;.TabHost (public class FileEditMainActivity extends Activity) &#8230;&#8230;&#8230;&#8230;&#8230;ImageView (public class FileEditImageView extends ImageView ) &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;Dialog (public class ColorPickDialog extends Dialog )<\/p>\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;View (private class ColorPickerView extends View )<\/p>\n<p>No matter how i change the Context the system tells my that the Context is not alive.<br \/>\nThe <code>ColorPickerView<\/code> is always crashing..<\/p>\n<p>Must say also that this is working if i dont use the <code>TabGroup<\/code>. When I put the <code>FileEditMainActivit<\/code> in the TabGroup something goes wrong with the Context.<br \/>\nAnyone have an ide of what to do?<\/p>\n<ol>\n<li>\n<p>Since everything is inside an ActivityGroup i hade to do like<\/p>\n<p>getparent().getParent()<\/p>\n<p>This might look brutal but it worked and for my level of experience im consider it to be a victory \ud83d\ude42<\/p>\n<p><strong>EDIT<\/strong><\/p>\n<p>the line <code>getparent().getParent()<\/code> would be the context parameter, eg:<\/p>\n<p><code>final ProgressDialog dialog = ProgressDialog.show(this.getParent().getParent(), null, \"Prcocessing\", true, true);<\/code><\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>I see there are like 10 answers for this question and i have read them all but cannot get this to work. Im moving my activity&#8217;s into this TabGroup and I have 3 activity&#8217;s inside a tabgroup and got help doing it from here: Multiple Android Activities in a TabActivity When opening a Custom Dialog [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2869","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2869"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2869\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}