Issue
What i am trying to do is getting getIntent(); in onResume. all thing is happening in MainActivity only
Here is my Code but its not working nothing is working
@Override
protected void onResume() {
Thread timer = new Thread() {
public void run() {
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent intent = getIntent();
String restaurant_name = intent.getStringExtra("restaurant_name");
Toast.makeText(MainActivity.this, restaurant_name, Toast.LENGTH_LONG).show();
if (restaurant_name != null) {
if (restaurant_name.equals("Romys")) {
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.89209, 75.82759), 15.0f));
mMap.addMarker(new MarkerOptions()
.position(new LatLng(26.89553, 75.82842))
.title("ROMYS"))
.showInfoWindow();
}
} else {
Toast.makeText(MainActivity.this, "It was not", Toast.LENGTH_LONG).show();
}
}
}
};
timer.start();
super.onResume();
}
I tried onResume onNewInent but app is crashing.
Solution
Not sure if that is all but you are trying to do a Toast on a thread that is not the main UI thread. So, try to replace your toasts like:
Toast.makeText(MainActivity.this, restaurant_name, Toast.LENGTH_LONG).show();
with code to run it on the main UI thread:
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, restaurant_name, Toast.LENGTH_LONG).show();
}
});
Answered By - user1626594
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.