0

I am looking to know how the actual alarm app popup the dialog box on exact time without any activity in background of it. If you could please see my this post for the exact solution i am looking for but answer to this question is much appreciated.

Code for popup

public void onCreate(Bundle savedinstance)
{
    super.onCreate(savedinstance); 
    //alarmsound = MediaPlayer.create(this, R.raw.wewillrock);
    alarmsound = new MediaPlayer();

        try {
            if(db.getAlarmCount()!=0)
            {
                Cursor alarmcursor = db.getAlarmdetails(this);
                if(alarmcursor!=null)
                {
                    alarmcursor.moveToFirst();
                    String alarmTonepath = alarmcursor.getString(alarmcursor.getColumnIndex(GinoClockDatabase.AL_RINGTONEPATH)); 
                    alarmsound.setDataSource(alarmTonepath);    
                    alarmsound.prepare();
                }
                db.close(); 
            }
            db.close();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block0
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        alarmsound.start();

    ((Activity)Global.context).finish();
    setContentView(R.layout.reminderpopupmessage);  
    settingViews(); 
}
private void settingViews() {
    yes = (Button) findViewById(R.id.btnReminderyes);
    no = (Button) findViewById(R.id.btnReminderno); 
}
@Override
public void onClick(View v) {

    switch(v.getId())
    {
    case R.id.btnReminderyes:
        alarmsound.stop();
        Intent splashscreen = new Intent(ReminderPopupMessage.this,SplashScreen.class);
        startActivity(splashscreen);
        ReminderPopupMessage.this.finish();
        break;
    case R.id.btnReminderno:
        alarmsound.stop();
        ReminderPopupMessage.this.finish();
        break;
    } 
}

I am looking more than a month for this solution but couldn't find the solution. I think i have asked more than 5 question about this alarm functionality. I hope i will get answer now.

Thanks for your help guys.

Community
  • 1
  • 1
vinothp
  • 9,939
  • 19
  • 61
  • 103
  • Create your own popup, and then show it! – Carnal Jul 09 '12 at 14:29
  • And in your xml file, set the Activitiy to be a dialog theme, in order to get the popup layout like this: android:theme="@android:style/Theme.Translucent.NoTitleBar" – Carnal Jul 09 '12 at 14:31
  • thanks for your comment carnal.. actually my alarm is working perfectly fine with the popup. the problem is when popup get displayed i am getting last used activity as a background.. if use see my post you will come to know what was the problem.. please see it my question – vinothp Jul 09 '12 at 14:34

2 Answers2

2

here is the link of Android alarm app git_alarm_app

AAnkit
  • 27,299
  • 12
  • 60
  • 71
1

Alright, I see your problem. In order to get rid of the background activity when displaying the popup, use this in your AndroidManifest.xml for the activity popping up as the alarm:

<activity android:name=".AlarmPopup" android:theme="@android:style/Theme.Dialog"
              android:clearTaskOnLaunch="true" android:launchMode="singleInstance" 
              android:finishOnTaskLaunch="true" excludeFromRecents="true"/>
Carnal
  • 21,744
  • 6
  • 60
  • 75
  • Thanks carnal.. It working like charm.. Many thanks for that because i am looking for this more than a month..+1 for that.. and it annoying that just from only one activity when i press home button it goes to the homescreen-->Alarm popups--> After that whenever i open the app it launches that activity.. i am really confusing.. Do u have any idea.. – vinothp Jul 09 '12 at 15:19
  • 1
    I don't really understand you. After the popup comes up? You pressed the home button and then when you start the application again it goes to that popup? You should implement then a close button on the alarm with the finish() method in order to remove it from the stack. Don't really understand what you mean. – Carnal Jul 10 '12 at 07:12