1

I'm trying to run SyncMe only when computer is pingable. Since the app currently is not able to work this way, I'm using Tasker and its AutoShortcut plugin. SyncMe exposes an intent/shortcut which allows to run all sync jobs for a given computer. Tasker was then configured to run such shortcut under certain conditions and every two minutes.

The problem is that the shortcut will only run "once", any subsequent calls to the shortcut will not run the sync. This happens not only from within Tasker but also when adding the shortcut to home screen. When tapping the icon for the first time, UI shows up and the sync runs correctly. But if I press home button and tap it again, it will only return focus to the UI without any action being taken.

The only way I could figure out to make the shortcut run again was somehow "closing" the app, for example going to home screen with the back button or removing SyncMe from recent apps, none of which seems possible from within Tasker, I think it requires rooting.

2 Answers 2

0

Android gives activities a setting called launchMode, which allows them to control how and when they're launched. With some values of launchMode, starting the same activity again with an intent won't start a new activity: instead, it'll deliver the new intent to the existing activity. This might happen only if the activity is the foreground activity, or if it is anywhere in the current task (that is, if you can get to that activity just by pressing back repeatedly).

It's quite common for app authors to set launchMode to solve some kinds of programming or user interface problem, such as concurrency issues that arise from having two instances of the same activity running at once, one in the foreground and one in the background. When they do this, they don't always remember to write the code to handle the new intent the activity is sent by Android: the activity receives the intent a different way to when it's first launched.

It's hard to tell without knowing more about this app, but from the behaviour you describe, it sounds like SyncMe has fallen into this trap. You should tell the developer what you're trying to achieve, and ask them to fix it.

2
  • @RenatoSilva I wouldn't suggest any flag. It's up to the app developer to fix this bug, either by resetting launchMode to normal, or by implementing onNewIntent.
    – Dan Hulme
    Sep 15, 2013 at 21:00
  • Dan, did you check it yourself? Try running shortcut, home button and then run shortcut again and you see that no intent is delivered no matter what launchMode is used. Looks like Android bug to me.
    – user41506
    Sep 16, 2013 at 4:46
0

Home screen shortcut

We believe it's an Android bug. In fact, as I could confirm on a custom build, adding FLAG_ACTIVITY_SINGLE_TOP fixed the problem for home screen shortcuts, despite its documentation indicating pretty the opposite, as below. We find those docs very poorly written, at least. According to the developer, this fix is going to work as long as main app activity stays on top (that is, editing a sync job then pressing home button for tapping icon again is not going to work).

If set, the activity will not be launched if it is already running at the top of the history stack.

Tasker and AutoShortcut

For some reason, the above fix does not work in AutoShortcut. I don't know how different the intent sent by this plugin is from that of the home screen shortcuts. Either way, I have reported the problem to the developer. Regardless, I also just have set up a direct intent configuration in Tasker, instead of using AutoShortcut, as follows:

  • Action: com.bv.wifisync.run
  • Extra: itemId:<id>
  • Package: com.bv.wifisync
  • Class: com.bv.wifisync.Hosts
  • Target: Activity

You must log in to answer this question.