Reason for 5 sec delay to show an activity on pressing the home button? - android-widget

I am facing delay of 5 sec to show an Activity after pressing the HOME key. I had gone through some post and found that after pressing the HOME button, android prevents services and broadcast-receivers from calling startActivity for 5 seconds.
Q1. Can anyone please let me know the reason to happening this delay ?
Q2. When I modified the ActivityManagerService::checkAppSwitchAllowedLocked() to always return true, it avoids checking lock and hence Activity gets shown without any delay. Would it be a good solution to avoid delay or it may cause any wrong effect in other ways ?

I know, it's probably too late (half year passed). However, here is the answer
You won't be able to get this permission on not rooted phone, unless your application is signed with the same keys as system. Android has some permissions like that.
Also, you may be interested to check this question. Starting an activity from a service after HOME button pressed without the 5 seconds delay

Related

RENODE How press a button for 5s and invert the methods Press and Release to be compatible with button with pullup configuration

I want to simulate in RENODE my stm32f030 to pressing a button for 5 seconds. But I have some problems related to the time and also with the RENODE method to simulate a Press and a Release of the button
In my firmware I configured the pin that is connected to the button as pull-up, that is, the button without pressing it has Status=TRUE. When the button is pressed, it goes to GND and Status=FALSE.
I did a 'debug' in the RENODE methods, I simulate a Press and then with the Pressed method it returns the status, you can check that:
Press results in True status
Release results in False status
Is there a possibility to reverse this method? Or do I put it as an alias in the robot framework? I found very little documentation, any light on my problem is already welcome
About the problem with time, when I execute the Press method and then the Release method and wait for close to 20 seconds it executes the action which is to blink together the Red and Blue LEDs, see below. However in my firmware it is configured to occur an interruption in the timer after 5s.
I read a bit about this in the official documentation (https://renode.readthedocs.io/en/latest/advanced/time_framework.html) and I suspect it is related to this, but I haven't identified what I need to do to fix it.
Reversing the state of a button is quite easy.
As in the miv-board.repl file, you can do the following:
user_switch_0: Miscellaneous.Button # gpioInputs 0
invert: true <--- this is relevant here
-> gpioInputs#0
Regarding time flow, Renode operates in virtual time domain to ensure determinism of execution, regardless of the host machine. It can be similar to real time flow, but depends heavily on the type of application you run. If you poll a lot and not use interrupts to sleep - things will be slower.
To get information about current virtual time you can run emulation GetTimeSourceInfo and see the output like this:
(machine) emulation GetTimeSourceInfo
Elapsed Virtual Time: 00:00:00.304409 <--- you want this to be 5s
Elapsed Host Time: 00:00:00.831891
Current load: 2.5
Cumulative load: 2.73280684868056
State: WaitingForReportBack
Advance immediately: False
Quantum: 00:00:00.000100

Way to update user while code is executing?

I'm creating a SwiftUI multiplatform app in XCode and I have a section of my code that hangs. I want to update the user so they know what's happening and are willing to wait. I originally planned to have an alert with text that changed and then planned to have a Text element that updated. In both cases this isn't shown until after the code executes and as such only shows the final message (normally the success done message unless an error made it end sooner).
Is there anyway I can have a visible message to the user through an alert or SwiftUI element that is updated right away and thus will be helpful?
The fact that the alert isn't even shown until after the code executes is bad and incorrect. This suggests that you are doing something lengthy on the main thread, and that is an absolute no-no. You are freezing the interface and you risk the WatchDog process crashing your app before the user's very eyes. If something takes time, do it in the background.

How to detect hardware key taps?

I am at a point where I need to detect if any of the hardware buttons was presses when the flutter app is in foreground or when it is open.*
For example, when someone presses a volume or another button (even if it is the power off one) I want to perform some action in my app.
I know that when a flutter app is open and I am looking at the app logs and I tap any hardware button is tapped the lops related to that tap is printed in the logs.
Like when I press Vol down Key Down Tap Detected related logs are printed in logs.
How do can I perform a function when any of the above specified action is performed?
New plugin called Hardware Buttons was released just a few days ago.
It supports volume button events and power button events, which seems like fits your need.
Maybe have a go with this?
You will need find the proper flutter packages to do so.
Any system level call needs to use the platform channel api
https://flutter.io/platform-channels/
Here is the repository
https://pub.dartlang.org/flutter/
Here is an example of a method channel.
https://github.com/flutter/plugins/blob/master/packages/device_info/lib/device_info.dart
Here is an example of a stream listener.
https://github.com/flutter/plugins/tree/master/packages/sensors
The stream listener wasn't really well documented when I tried to grab mic fragments.

ItemClickListener kicking off while ItemLongClickListener happens

The best way I can describe this is the following. I have a poster gallery that has a bunch of images. The selected poster gets highlighted as the user moves back and forth through the gallery. I have the following code set on the poster gallery:
Gallery posterGallery = (Gallery) context.findViewById(R.id.moviePosterGallery);
posterGallery.setAdapter(new MoviePosterImageGalleryAdapter(context, key,
item.getCategory()));
posterGallery.setOnItemSelectedListener(
new MoviePosterOnItemSelectedListener(bgLayout, context));
posterGallery.setOnItemClickListener(new MoviePosterOnItemClickListener());
posterGallery.setOnItemLongClickListener(new MoviePosterOnItemLongClickListener());
What seems to happen is if you press the Remote on the vizio costar, both the Click and Long click events are being fired if you hold down the OK button. As in my case a dialog pops up when a Long click is received, but also the poster launches the video related to that to start playing which is part of the ItemClickListener code..
When testing the same code on a Nexus 7 tablet, only the long click is fired, not both. Is there a way to handle the long click correctly on Google TV. I'm using a vizio costar with Google TV 3 if that helps.
Also, if you move the mouse pointer over the item, and then hold down the - key on the front of the remote, only the long click event is triggered. It just seems to be related to the OK and how long that held down.
I looked at the following similar issue:
onListItemClick and onItemLongClick Google TV
but I already have the onItemLongClick returning true when it handles the event.
There is a quirk with the Vizio remotes. The OK button is not mapped to the right keycode. The Vizio remote sends KEYCODE_ENTER when OK is pressed when in fact it should be sending KEYCODE_DPAD_CENTER. This is what is causing your issue I think. If you try using AbleRemote as the input device you should be able to see it working as expected. Now to solve your issue you may have to go to a keycode listener if a keyboard is present and detect the key events on the posterGallery to fire off short and long clicks.

On Android or iOS - how to approach the possibility of a service or app going into a broken state

...and this broken state persisting until a device restart, since a naive attempt to restart an app would not work. Many users are not savvy enough to know how to terminate services/backgrounded apps. If the user can't (or doesn't 'need to') close apps, then what about restarting apps which have gone wrong? ( It can happen :) ) If my app goes wrong on someone's phone and they cannot easily restart the app without restarting the phone, that seems like a problem. I am aware that apps and services can be terminated by navigating system menus or double tapping the home button etc. but - many users are not aware of these features. For this reason I am thinking of adding an explicit close button to my app which will kill everything to the best of my ability, such that on a subsequent launch the program runs from the beginning again. I realise this is not the 'recommended' approach. Thoughts?
Thoughts?
Don't do it. Instead you should put a FAQ entry on your apps website that says.
Q: My app does not run anymore. HELP!
A: First you should try to restart the app. If that doesn't work feel
free to contact me.
Here is how you do this on the iPhone,
iPad or iPod.
double press the home button. the
multi tasking bar appears.
[ some screen shots ]
long press the app icon and press the
little x that appears on the icon.
[ more screenshots ]
If you want to put buttons for functions that are not obvious for many users you end up with a button for everything. And I (as somebody who knows every function) don't want a button cluttered user interface.
You would be surprised how many emails I get about "how can I zoom?" (A: Pinch your fingers) or "how do I delete an entry (in a tableview)" (A: Swipe your finger over the entry from left to right, and press the red delete button).
If I get an email about this I just point them to the faq which has some nice screenshots.
Btw, if the "broken state" happens so often that you would consider adding a special button I would check my code for bugs again.