Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting up Alarm Manager is creating 2 Instances of my Main Activity
    primarykey
    data
    text
    <p>I have 2 activities, a Main Activity and SetAlarm Activity. I call SetAlarm Activity from Main. When I set up the alarm I create an instance of my main. How do I set up the alarm without creating another instance of the Main or do I kill the main before setting up the alarm? Quite new to this. I have read several of the alarm manager examples, but they all seem to set up a new intent and I think this is what is creating my 2 instances. Is this how you set up the alarm. It does go off. </p> <p>Here is how I call SetAlarm from the Main:</p> <pre><code>public void setAlarm(View view) { Intent intent = new Intent(this, SetAlarmActivity.class); startActivityForResult(intent, 2); } </code></pre> <p>Here is how I set up the Alarm:</p> <pre><code>public void setUpAlarm() { if (VERBOSE) Log.v(TAG, "+++ IN setUpAlarm +++"); PLAY_MUSIC = "Y"; Intent intentAlarm = new Intent(this, MainActivity.class); intentAlarm.putExtra("playMusic",PLAY_MUSIC); intentAlarm.putExtra("mPos", mPos); intentAlarm.putExtra("result",ALARM_SET); setResult(RESULT_OK,intentAlarm); pIntent = PendingIntent.getActivity(this, 12345, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager)(this.getSystemService( Context.ALARM_SERVICE )); am.set(AlarmManager.RTC_WAKEUP, calSet.getTimeInMillis(), pIntent ); } // setAlarmPlaySong </code></pre> <p>I cut the alarm off in the main:</p> <pre><code>@Override public void onResume() { if (VERBOSE) Log.v(TAG, "+++ IN onResume +++"); super.onResume(); Intent intent = getIntent() if (intent.hasExtra("playMusic") &amp;&amp; intent.hasExtra("mPos")) { playMusicFlag = intent.getStringExtra("playMusic"); mPos = intent.getIntExtra("mPos", 0); if (playMusicFlag.equalsIgnoreCase("Y")) { if (VERBOSE) Log.v(TAG, "+++ playMusicFlag is SET+++"); playSongs(); showStopAlarmButton(); } // if } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload