Note that there are some explanatory texts on larger screens.

plurals
  1. POStarting Activity problems in AsyncTask in android
    text
    copied!<p>I am facing one problem in <code>AsyncTask</code> in my application in Android. The problem is, I am starting another <code>Activity</code> from <code>AsyncTask</code> in my application which runs fine when its layout has simple <code>Button</code>, but when I am using <code>ImageButton</code> its giving me error of handler and looper.loop. I am not getting the reason why this kind of error is occurring. I am displaying menus with images in calling <code>Activity</code>. </p> <p>Can anybody suggest me what is the problem in this and how can I achieve this kind of functionality?</p> <pre><code>protected void onPostExecute(Void result) { super.onPostExecute(result); if (Dialog != null &amp;&amp; Dialog.isShowing()) { Dialog.dismiss(); locationManager.removeUpdates(locationListener); Intent homeIntent = new Intent(ATMActivity.this.getApplicationContext(), HomeMenuActivity.class); homeIntent.putExtra("lat", latitude); homeIntent.putExtra("lng", longitude); startActivity(homeIntent); } } </code></pre> <h3>XML File :-</h3> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" &gt; &lt;ImageButton android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/atm_icon" android:onClick="buttonClicked" /&gt; &lt;/LinearLayout&gt; </code></pre> <h3>Another Activity Class :-</h3> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home); Button btn = (Button) findViewById(R.id.imageButton1); btn.setHint("ATM"); float latitude = getIntent().getFloatExtra("lat", 0); float longitude = getIntent().getFloatExtra("lng", 0); Toast.makeText(getApplicationContext(), "Location Floats:- " + latitude + "," + longitude, Toast.LENGTH_LONG).show(); } </code></pre>
 

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