Showing a Toast or Activity on top of another application


Last Updated:

  1. Sir^Knigget

    Sir^Knigget Member This Topic's Starter

    Joined:
    Sep 30, 2009
    Messages:
    11
    Likes Received:
    0
    Hello,
    I have an application which runs a background thread which eventually updates listeners on some incoming event.
    When I'm in this listeners' code, I want to be able to either show a Toast or a new Activity on top of the screen, regardless of what is running in this moment - but to be able to come back to it (add on top of the current stack, even if it's another application).
    By now I didn't succeed in doing that in any way.

    This is one attempt (inside my listener, which is called from a worker thread):

    Code (Text):
    1. runOnUiThread(new Runnable() {
    2.                          
    3.                          public void run() {
    4.                               Toast.makeText(getApplicationContext(), "toast", Toast.LENGTH_LONG).show();
    5.                                
    6.                          }
    7.                     });
    8.  
    It shows the toast when I am in my original application, but not when I'm in background.
    I put a breakpoint on the line with the toast showing, and I know that I get there, but it does nothing.

    Do you have any idea?

    Thanks ahead!
     

    Advertisement
  2. KlaymenDK

    KlaymenDK Well-Known Member

    Joined:
    May 29, 2009
    Messages:
    1,217
    Likes Received:
    130
    Where do you get your Context from?

    I think you need to regard everything inside that run() block as a standalone application, with its own initialisers. That is to say, you can't expect the call to getApplicationContext() to work against any Context you've defined outside the scope of your Runnable block.
     
  3. Sir^Knigget

    Sir^Knigget Member This Topic's Starter

    Joined:
    Sep 30, 2009
    Messages:
    11
    Likes Received:
    0
    Could you elaborate on that?
    How could I create an entirely new context from my Runnable?
    The Context comes from the activity that the listener is in - the activity sets the listener at some stage, and then gets to the background.
     

Share This Page

Loading...