Note that there are some explanatory texts on larger screens.

plurals
  1. POError Receiving broadcast Intent ACTION_BATTERY_CHANGED
    primarykey
    data
    text
    <p>I am trying to get battery information through the use of a broadcast receiver and store it in a database. I'd prefer to get it only when I specifically want it, but I am willing to keep a database of just running records of it. Anyways, The problem is my app crashes with this error:</p> <pre><code>java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.BATTERY_CHANGED flg=0x60000010 (has extras) } at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:765) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4918) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771) at dalvik.system.NativeStart.main(Native Method) Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f04006b at android.content.res.Resources.getText(Resources.java:242) at android.widget.TextView.setText(TextView.java:3773) at com.Eddiecubed44.drunk.buddy.Main$2.onReceive(Main.java:180) at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:755) </code></pre> <p>And when i say crash, I mean crash and burn. My phone restarts itself every time I run it with this code in it.<br> I've stepped through with the debugger and haven't caught the error. I create the broadcast Receiver in my main activity class as so:</p> <pre><code> BroadcastReceiver batteryReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int temp = -1; TextView tempText; tempText = (TextView)findViewById(R.id.mybatttemptxt); temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1); tempText.setText(R.string.temp + temp); </code></pre> <p>This is how im registering the Broadcast Receiver.</p> <pre><code>this.registerReceiver(this.batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); </code></pre> <p>I do this in my onStart Method. The thing is, I can run my app if i replace this.batteryReceiver with null, but the app does nothing. The receiver is not called or used anywhere else in this app. </p> <p>If it matters heres what I'm using: testing on rooted galaxy s3 app is using target lvl15 api min 11.</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