Basically I am trying to make an activity containing a button which reboots the device and after the reboot returns to the same activity.
I understand that this question may get confused with others about rebooting the device, but that is not the focus of this question as I can get the device to reboot fine.
I have made the button reboot the device but the only way I can get it to start the activity after it's finished rebooting is to register a broadcast receiver for BOOT_COMPLETED in the manifest. The trouble is that this method starts the activity every time the device boots which is undesirable. When I register the receiver on the button click listener it does not start the activity after the reboot.
I was wondering if there might be an extra in BOOT_COMPLETED that I could use to decide if it had been purposefully rebooted.
Any advice would be appreciated, thanks in advance!
Just save an integer corresponding to device purposely being rebooted through your activity. Use SharedPreference for the same. On reboot, in your broadcast receiver, check if the value is set. If it is set, start your activity, otherwise, let it go.
EDIT :
Always, unset this value when reboot is complete and your Activity is in front.
Your XML should be stored in a file named AndroidManifest.xml, not manifest.java.
Another reason your code is not being run, might be that your App is installed on external storage (sdcard). BOOT_COMPLETE is sent to applications before external storage is mounted. So if application is installed to external storage it won't receive BOOT_COMPLETE broadcast message.
If that isn't the problem, there is already a very good description of how to get boot completed receivers working on Android.
Trying to start a service on boot on Android
Related
I am developing a custom dailer App incoming call screen but my problem is that when the app is in foreground, on incoming call the broadcast receiver is called and displays the custom screen but when the app is in the background or not in running state then the broadcast receiver is not called.
How to resolve this?
And Also Getting this Log
ConnectionTracker: Exception thrown while unbinding
java.lang.IllegalArgumentException: Service not registered: lt#3e5af9d
On some devices (notably low-end and Chinese manufacture) apps are not permitted to perform background activities if they are not in a list of "protected apps". This is done to save battery life. If your device does this, it will not launch a BroadcastReceiver if the app is not already running. To fix this you will need to manually add your app to the list of "protected apps" or "apps allowed to perform background activities". There is a setting in the Android settings for the user to maintain this list of apps. It is usually in the "Security" or "Power management" settings somewhere.
I would like to know if an Application such as whatsapp or youtube is opened by the user. Looking at the logcat, I can see that when the activity of the whatspp is opened - following
com.whatsapp.intent.action.CHATS
intent actions is opened. Am looking for a way to log this - so I can run an algorithm to suggest which page of the application will be opened at a given point of time
There are some broadcasts that require explicit registering in the system (Annotated with You can not receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver().).
The most important ones for apps that run code after installing are:
ACTION_USER_PRESENT: Sent when the user is present after device wakes up (e.g when the keyguard is gone).
ACTION_SCREEN_ON: Broadcast Action: Sent when the device wakes up and becomes interactive.
ACTION_SCREEN_OFF: Broadcast Action: Sent when the device goes to sleep and becomes non-interactive.
ACTION_MY_PACKAGE_REPLACED: A new version of your application has been installed over an existing one. This is only sent to the application that was replaced. It does not contain any additional data; to receive it, just use an intent filter for this action.
ACTION_HEADSET_PLUG: Wired Headset plugged in or unplugged. Same as ACTION_HEADSET_PLUG, to be consulted for value and documentation.
ACTION_DATE_CHANGED: The date has changed.
I am developing an app which records unlocks of mobile. But I am having problem when my app is manually killed i.e. when you remove app from recent apps. How can i record broadcast even when app is killed?
I am using ACTION_USER_PRESENT for recording unlocks.
You'll need to create a Service and inside this service create the broadcast receiver that you need.
This answer Certainly will help you : Implement Broadcast receiver inside a Service
I'm trying to discover Chromecast device on my network, select it and use for video streaming in a newly launched activity. It all works fine until I exit my "streaming" activity and return to "discovery" activity. I start a new discovery upon return to this activity and this time it is not finding my device (onRouteAdded() never called).
I call mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
in onResume() and mMediaRouter.removeCallback(mMediaRouterCallback); in onPause().
Is there anything else I need to do to restart discovery process? Note that I don't use MediaCast button and handle RouteAdded/Removed and selection manually.
Thanks.
I am working on an Android project that has a part which dose this:
1) the user enter a data from a data field and save it in a text file
2) the app should send notification even if the application is killed by the os, at that date, the one wrote by the user.
For example:
I write 31.01.2015
The app will notify my only on 31.01.2015 even if i don't open that app anymore.
The question is how do i have to do this?
Thanks!
It sounds like you want a notification to be posted to the notification bar.
If so I advise using an alarm.
However, chances are if this is days in the future, the phone may be shut off. So you should store when the alarm should go off, create a Broadcast receiver for the on boot complete event (this requires a permission), and re-setup the alarm when the boot is complete.
This should allow the notification to appear, independent of the apps life-cycle, as long as the app is not uninstalled.
Note: You will have to calculate the milliseconds between the date for the alarm, and the current time. Calendar should help.