1. Download our Official Android App: Forums for Android!

Apps custom dialog from an activity shows a window from another

Discussion in 'Android Development' started by intentreceiver, Jul 22, 2011.

  1. intentreceiver

    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    15
    Joined:
    Jul 21, 2011

    Jul 21, 2011
    15
    1
    16
    So I'm displaying an AlertDialog (1), but with it appears a little window that should not be there (2).
    [​IMG]
    This is the xml code for the Activity I'm displaying it from that should avoid displaying anything outside the activity.
    Code (Text):
    1.       <activity android:name="Alarm"
    2.                   android:theme="@android:style/Theme.Dialog"
    3.                   android:launchMode="singleInstance"
    4.                   android:excludeFromRecents="true"
    5.                   android:taskAffinity="">
    6.         </activity>
    The window also appears when I do something like this:
    Code (Text):
    1.         Dialog dialog = new Dialog(this );
    2.         dialog.setContentView(R.layout.myAlarm);
    3.         dialog.setTitle("Custom Dialog");
    4.         dialog.show();
    But it never appears when I just call
    Code (Text):
    1. setContentView(R.layout.myAlarm);
     

    Advertisement

  2. alostpacket

    alostpacket Over Macho Grande?
    Rank:
    None
    Points:
    513
    Posts:
    7,972
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,972
    3,603
    513
    Android App Developer
    NY
    Why not define the dialog layout xml separately, and define the activity layout as having a transparent BG? (0x00000000)

    Something to try anyways

    hth
     
  3. intentreceiver

    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    15
    Joined:
    Jul 21, 2011

    Jul 21, 2011
    15
    1
    16
    The Activity that is shown on the screen isn't the one the dialog is created in. The one on the screen is the MainActivity (the main UI), although it is missing all of its components (buttons etc). And those custom dialogs look fugly by default and I really don't want to put work into making a good one. There must be a way to stop the MainActivity window from displaying with my dialog..
     
  4. alostpacket

    alostpacket Over Macho Grande?
    Rank:
    None
    Points:
    513
    Posts:
    7,972
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,972
    3,603
    513
    Android App Developer
    NY
    All I can think of is that you can have
    excludeFromRecents in there on the main activity. But that could cause other problems, not really a solution I think.

    Question though, how do you start the alarm activity? I think this might be an important peice to the puzzle. The activity with the dialog should be receiving an intent to launch it, or be launched from a Service or Broadcast Receiver.

    However it might just not be possible -- why do you want such a dialog anyways?

    You probably could use a sytem alerts but that permission really isnt meant for apps.
     
  5. alostpacket

    alostpacket Over Macho Grande?
    Rank:
    None
    Points:
    513
    Posts:
    7,972
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,972
    3,603
    513
    Android App Developer
    NY
    Actually I think if you change the affinity and/or launchMode to singleTop and set allowReparenting to true you might get what you're looking for. Worth a try I think

    <activity> | Android Developers
     
  6. alostpacket

    alostpacket Over Macho Grande?
    Rank:
    None
    Points:
    513
    Posts:
    7,972
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,972
    3,603
    513
    Android App Developer
    NY
    Like, as far as I follow what they say in the docs, "singleTask" means essnetially "put all my activities together in a singleTask" So that might be the problem.

    hth
     
  7. intentreceiver

    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    15
    Joined:
    Jul 21, 2011

    Jul 21, 2011
    15
    1
    16
    I have a broadcastreceiver that onReceive creates a new Intent, adds some info to it and sets the (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION) flags. Then I start it with context.startActivity(intent);
    After some analysis and tests it appears what I'm looking for is a way to show a dialog without displaying the Activity it belongs to (and the MainActivity window displayed is still the activity I launch the dialog from, so my previous post is a bit incorrect). Transparency stuff is probably one option, but I'm hoping there are better ones out there.
    As for changing the affinity, launchMode and allowReparenting - that unfortunately had no effect.
     
  8. intentreceiver

    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    15
    Joined:
    Jul 21, 2011

    Jul 21, 2011
    15
    1
    16
    okay, I've pretty much accomplished what I was going for with an invisible theme and calling finish() upon the close button being pressed.
    thanks for help!
     

Share This Page

Loading...