What can I do to make the Headless JS service run in foreground in android? - react-native

I went through official documentation of the React Native Headless JS. In the caveats, It is mentioned that if the app will try to run the task in foreground, the app will crash.It is also mentioned that there is a way around this.Please suggest a way so that I can have heavy tasks done in an another thread other than the UI thread using Headless JS when the app is in the foreground.

It worked for me to use the HeadlessJsTaskService, even when started from a currently active Activity. Did you try it and it crashed?
Edit
I had a look at their implementation.
Your app will crash under the following conditions:
if (reactContext.getLifecycleState() == LifecycleState.RESUMED &&
!taskConfig.isAllowedInForeground()) { //crash }
(see ReactContext)
This means that you can configure the HeadlessJsTaskConfig within your HeadlessJsTaskService with a true for allowedInForeground.
E.g.
#Override
#Nullable
protected HeadlessJsTaskConfig getTaskConfig(Intent intent) {
Bundle extras = intent.getExtras();
WritableMap data = extras != null ? Arguments.fromBundle(extras) : null;
return new HeadlessJsTaskConfig(
"FeatureExecutor",
data,
5000,
true /* Don't crash when running in foreground */);
}
But in my test-case this step was not necessary, even when displaying a ReactRootView. I think the reason for that is, that the ReactRootView had its own ReactContext (which might not be a good idea).
For your implementation you should consider the following when using Headless JS:
allowedInForeground whether to allow this task to run while the app is in the foreground (i.e. there is a host in resumed mode for the current ReactContext). Only set this to true if you really need it. Note that tasks run in the same JS thread as UI code, so doing expensiveoperations would degrade user experience.
(see HeadlessJsTaskConfig.java)

Related

Webview browser application not open the dynamic links of Google Forms either dynamically or directly

I built a Webview browser application on an Android 11 device that knows how to open all links perfectly! But it does not open the dynamic links of Google Forms either dynamically or directly (when I copy the final address that opens on my computer), the application completely crashes and closes! I did not find any useful information on Google only regarding dynamic links to Firebase - I added the functionality as required, but to no avail! For Dodge:
Dynamic: https://forms.gle/uJq3pGPJhqZGYzLC6
, Direct: https://docs.google.com/forms/d/e/1FAIpQLSd8PZt648GmhALFyykBTflSiU8b9_e-h3gVfY6ZBcF9-N0HbQ/viewform
Dynamic: https://docs.google.com/forms/d/e/1FAIpQLScnkyROLo8VavCmaRagZb6eiucxjCdkOs6blijHwe34vFXO6g/viewform?usp=sf_link ,
direct: https://docs.google.com/forms/d/e/1FAIpQLScnkyROLo8VavCmaRagZb6eiucxjCdkOs6blijHwe34vFXO6g/viewform
I tried to add dynamic links to the firebase SDK, and In AndroidManifest.xml, add an intent filter to the activity that handles deep links for your app. And I also called to call the getDynamicLink() in OnCreate() but the links never reached this event.
Direct reading ON 'shouldOverrideUrlLoading' didn't help either because the application crashes before it gets here, that is, something goes wrong with the dynamic search and even in debugging it disrupts the URL completely:
public boolean shouldOverrideUrlLoading (WebView view, String url) {
if(url.contains("https://docs.google.com/forms/") && url.contains("/viewform"))
{
try {
url= "https://"+ url.split("https://")[url.split("https://").length-1].split("viewform")[0].trim()+"viewform";
}
catch (Exception e)
{
Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG).show();
url = "https://www.google.com";
}
}
mWebView.loadUrl(url);
return true;
}

How should I run a background task that also updates the UI in an intellij settings plugin

I am adding some changes to an intelij plugin that integrates with vault I have settings page that implements Configurable that has a form for credentials and then a "Test Login" button. On button click I want to spawn an asynchronous background task to test the credentials and then update the UI with either success or failure.
Here is a screenshot of my settings
As far as I can tell the correct way to do this would be to use a background task but that requires a "project" which as far as I can tell you have to get from an AnAction and I don't really see how that would work in this context. Here are a few approaches I've played around with
This still blocks the UI and spits out a warning about the UI being blocked for too long
ApplicationManager.getApplication().executeOnPooledThread(() ->
ApplicationManager.getApplication().invokeLaterOnWriteThread(() -> {
// async work
// repaint
}, ModalityState.stateForComponent(myMainPanel)));
// I don't know how to get the project or if I even should here.
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Login"){
public void run(#NotNull ProgressIndicator progressIndicator) {
// async work
// repaint when done
}});
All of this is happening in my AppSettingsComponent button click addActionListener. Here is my complete source code on github
I had the same problem with the project instance required. But by looking at the Task.Backgroundable constructor you can pass a #Nullable project. So I just pass null and it works well for me.
ProgressManager.getInstance().run(new Task.Backgroundable(null, "Login") {
public void run(#NotNull ProgressIndicator progressIndicator) {
// your stuff
}
});

branch io integration with Adobe air app issue

Our iOS app is live in iTunes, and we want to integrate it with Branch io. We can build the ipa for testing, but when we try to "Export Release Build", the Flash Builder 4.6 will hang.
This is the branch io guide that we are following:
https://dev.branch.io/getting-started/sdk-integration-guide/guide/adobe/
We just followed the steps, and put in the stuff up to step 4, where we called
branch.init() in the main class. The setting in branch io is setup ok.
here are the codes, (just copied from branch io's website)
// Then create a Branch instance:
var branch:Branch = new Branch();
// Register two events before initializing the SDK:
branch.addEventListener(BranchEvent.INIT_FAILED, initFailed);
branch.addEventListener(BranchEvent.INIT_SUCCESSED, initSuccessed);
private function initFailed(bEvt:BranchEvent):void {
trace("BranchEvent.INIT_FAILED", bEvt.informations);
}
private function initSuccessed(bEvt:BranchEvent):void {
trace("BranchEvent.INIT_SUCCESSED", bEvt.informations);
// params are the deep linked params associated with the link that the user clicked before showing up
// params will be empty if no data found
var referringParams:Object = JSON.parse(bEvt.informations);
//trace(referringParams.user);
}
// Initialize the SDK:
branch.init();
Any clues?

Notification in Tizen wearable web app to display the UI of app running in background

In the tizen wearable web application that I am developing, I need my application to prompt a notification to the user every 10min to go into the same application and give some sort of input from the app UI.
I am currently using a simple status notification from notification API which gives a notification having link to the current application. When user clicks on it, the application is launched again (as it does according to description in simple status notifiation).
But I don't want the application to be restarted by clicking on the notification. Instead it should get the application running background to display on the watch UI.
Please let me know any possible solutions to achieve this.
Below is the code I am using right now.
var myappInfo = tizen.application.getAppInfo();
var notificationDict = {
content : "Please enter your response.",
iconPath : "images/icon.png",
vibration : true,
soundPath : "music/solemn.mp3",
appId : myappInfo.id
};
currentBatteryLevelNotification = new(tizen.StatusNotification("SIMPLE",
"Your input required!", notificationDict);
tizen.notification.post(currentBatteryLevelNotification);
I tried playing with your code, got some progress using:
AppContextId
var myappInfo = tizen.application.getAppContext();
//appId : myappInfo.id or muappInfo.appId
and Moving app to background:
document.addEventListener('tizenhwkey', function(e) {
if(e.keyName === "back") {
try {
tizen.application.getCurrentApplication().hide();
//instead of tizen.application.getCurrentApplication().exit();
} catch (ignore) {
}
}
});
config.xml:
<tizen:setting background-support="enable" encryption="disable" hwkey-event="enable"/>
Tip: If you don't add background-support for Web application, it just dies once you are on exit, It's not possible to get current state.
But I assume the answer is No. May be Notification API is not designed to launch running application I guess.

Adding PatternMatchListener to Eclipse Console in which stage of View Lifecycle

I am developing an Eclipse plug-in which will be triggered by a specific pattern string found (e.g., stack trace) in the default console opened in Eclipse and will show some notification in a custom view. I know how add the listener to the available consoles.But I am not sure in which phase of Eclipse View life cycle I need to add the listener. Currently I am adding in createPartControl which is not what I want, because it forces to me to open the view manually to perform the binding the listener with the consoles.
public void createPartControl(Composite parent) {
//got the default console from ConsolePlugin
TextConsole tconsole=(TextConsole)defaultConsole;
tconsole.addPatternMatchListener(new IPatternMatchListener() {
// implementation codes goes here
}
}
Any help will be appreciated.