Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Broadcast receiver gives Error
    text
    copied!<p>Got another problem. Trying to use a broadcastreceiver to catch off an Alarm (alarm manager).</p> <p>The following code is used: package com.suncco.shangxinbao.service;</p> <pre><code>import java.util.Calendar; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; import android.widget.Toast; import com.suncco.shangxinbao.model.ScheduledSms; public class SmsTimerService extends BroadcastReceiver { public SmsTimerService(Context context, int timeoutInSeconds, ScheduledSms sms) { Intent myIntent = new Intent(context, SmsTimerService.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, sms.getRequestCodeForListener(), myIntent, 0); AlarmManager alarmManager = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 5); // should be timeoutInSeconds instead of 5 alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); } @Override public void onReceive(Context context, Intent intent) { Log.w("Karl", "yay"); } </code></pre> <p>In the manifest I put this as receiver:</p> <pre><code> &lt;receiver android:name="com.suncco.shangxinbao.service.SmsTimerService" android:process=":remote" /&gt; </code></pre> <p>And I make an object of my SmsTimerService like this:</p> <pre><code> SmsTimerService smsTimerService = new SmsTimerService(this,5,sms); </code></pre> <p>And this is the well known error...</p> <pre><code>java.lang.RuntimeException: Unable to instantiate receiver com.suncco.shangxinbao.service.SmsTimerService: java.lang.InstantiationException: com.suncco.shangxinbao.service.SmsTimerService </code></pre>
 

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