Note that there are some explanatory texts on larger screens.

plurals
  1. POCall a method from Activity on BroadcastReceiver called by an AlarmManager
    primarykey
    data
    text
    <p>I'm new to asking, so I hope my question is correctly asked. Thanks in advance!</p> <p>My problem is:</p> <p>A <code>BroadcastReceiver</code> is called by an <code>AlarmManager</code> in this way by a method inside the same <code>BroadcastReceiver</code>:</p> <pre><code>AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, Receiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0); am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 5000, pi); </code></pre> <p>onRecieve works until I put there the method from <code>MainActivity</code>. When the call is on the code, i get this error every time the <code>AlarmManager</code> tries to start the onReceive:</p> <pre><code>12-22 21:56:01.020: W/BroadcastQueue(2192): Unable to launch app com.example/10000 for broadcast Intent { flg=0x14 cmp=com.example/.Receiver (has extras) }: process is bad </code></pre> <p>If I create a method on the <code>BroadcastReceiver</code> that recieves <code>MainActivity</code>, I can call methods from <code>MainActivity</code> inside that method of BroadcastReceiver:</p> <pre><code>public void SetHandler(Context context, MainActivity main) { MainActivity mainactivity; this.mainactivity = main; mainactivity.method(); } </code></pre> <p>But I can't understand how to call them inside the onReceive of the BroadcastReceiver.</p> <p><code>mainactivity.method()</code> on the onRecieve doesn't work, I don't know if it is because it is not attached to the <code>MainActivity</code> by the <code>AlarmManager</code> or if it is because I'm doing it wrong.</p> <p>If the problem is because of the attachment of the activity with the BroadcastReceiver, how is it done? If that's not the problem, what would it be?</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.
 

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