2

When my app is in foreground, a notification from random application comes up and when user clicks on that notification, my app goes to background. The problem is with toast that is displayed by my App after completing the task, it appears even my app went to background which is creating confusion to users. They thought the toast was from random app which is in foreground.

Any idea on how to solve this?

harshal
  • 592
  • 6
  • 25
  • This may not be the best way, but it is a hack together. Have you tried setting a variable in your onPause method of your activity, something like boolean isInForeground = false; then in onResume isInForeground = true; and then with your Toast say if(isInForeground){ Toast.makeText...;}. – zgc7009 Mar 13 '14 at 14:12
  • my understanding is app goes to Background means GUI thread is suspended state so Toast display code part should not have been executed... – harshal Mar 13 '14 at 14:25
  • Depends on how you are handling the toast, could you post your code. – zgc7009 Mar 13 '14 at 14:30

1 Answers1

1

You can either prevent the Toast from appearing if your app is in the background or use a library like Crouton:

Context sensitive notifications for Android

Community
  • 1
  • 1
Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144