Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure if the second argument in the onReceive() method is the intent from Activity. Its the AlarmManager who's firing up the receiver, not your activity. If i'm right, my mind has only one solution for your problem - file stored externally, containing your alarm's start time.</p> <p>It goes like this:</p> <ol> <li><p><code>Activity</code>:</p> <pre><code>// Remember about adding // &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt; // in your manifest xml File file = new File(Environment.getExternalStorageDirectory() + "/yourAppsName", ".alarmStartTime"); try { BufferedWriter out = new BufferedWriter(new FileWriter(file.getAbsolutePath(), true)); out.write(SystemClock.elapsedRealtime()); out.close(); } catch (IOException e) { Toast.makeText(this.getApplicationContext(), "Problem", Toast.LENGTH_SHORT).show(); } </code></pre></li> <li><p><code>BroadcastReceiver</code>:</p> <pre><code>File file = new File(Environment.getExternalStorageDirectory() + "/yourAppsName", "alarmStartTime.txt"); String content = ""; try { content = new Scanner(file).useDelimiter("\\Z").next(); } catch (FileNotFoundException e) { Toast.makeText(this.getApplicationContext(), "Problem", Toast.LENGTH_SHORT).show(); } Log.i("", "Alarm Running for " + (SystemClock.elapsedRealtime() - Long.decode(content))); </code></pre></li> </ol> <p>Although, its a cpu and battery killer if you'd run it every 2 seconds;)</p> <p>Tell me again why can't you use this static variable? If you have specific interval between alarms, number of iterations can simply inform you about life span of the receiver.</p>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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