[Tasker] Background service cannot start foreground activity
Hello,
The following code only work when main app activity is open or recently open. In the case of intent received from tasker trigger without application activity in the foreground back stack it doesn't work.
Related Android documentation : https://developer.android.com/guide/components/activities/background-starts
To let it work on my device, I made the following ugly but functional change. I let you implement your way.
public static void startWithFixedDNS(final Context context, ArrayList<IPPortPair> upstreamServers, boolean startedWithTasker) {
LogFactory.writeMessage(context, LOG_TAG, "[STATIC] Starting with fixed DNS. Started with tasker: " +startedWithTasker);
LogFactory.writeMessage(context, LOG_TAG, "[STATIC] " + upstreamServers);
if (startedWithTasker) {
Util.startService(context,
DNSVpnService.getStartVPNIntent(context, upstreamServers, true, true));
} else {
Intent i = new Intent(context, BackgroundVpnConfigureActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra("fixeddns", true)
.putExtra("servers", upstreamServers)
.putExtra("startService", true)
.putExtra("startedWithTasker", startedWithTasker);
context.startActivity(i);
}
}