BroadcastReceiver runs when the program is not running. For debugging, I wanted to see Toast , which was specified in the onReceive() method. But there was no message, as well as indications of errors. Why?
|
1 answer
- The receiver must be declared in the manifest.
- The receiver must be described in a separate java-file.
- The receiver must be registered in the system. To do this, the application must start at least once after installation and / or forced stop.
- The receiver should receive some messages. Maybe he just got nothing.
Without a code, nothing more concrete will be told to you here - all psychics on vacation.
- You are absolutely right. The question was asked from memory, and the memory let me down. I promise to recheck next time. In general, from onReceive () Toast is indeed visible. It is not visible from onHandleIntent () IntentService, which is started in onReceive (). Here's the code: Toast.makeText (getApplicationContext (), "FROM onHandleIntent ()", Toast.LENGTH_LONG) .show (); Log.d ("-----------------", "FROM onHandleIntent ()"); There is a message in the log, but there is no toast. So why is Toast not visible. The point is probably in context? - iramm
- @iramm; Maybe yes - the point is in context. Try using the service context, i.e. just
this- Yuriy SPb ♦ - Still not visible. Maybe I’d better remove the question as incorrectly worded. How do you think? - iramm
- Helped: Handler handler = new Handler (Looper.getMainLooper ()); handler.post (new Runnable () {@Override public void run () {Toast.makeText (getApplicationContext (), "FROM - iramm
- one@iramm, do not delete. The question is about the receiver, but everything is correctly written about it. You can simply add your solution here in the question supplement or answer. Indicating that the output was needed from the service. - Yuriy SPb ♦
|