Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • D DnsChanger
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 32
    • Issues 32
    • List
    • Boards
    • Service Desk
    • Milestones
  • Jira
    • Jira
  • Merge requests 1
    • Merge requests 1
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • PublicAndroidApps
  • DnsChanger
  • Issues
  • #144
Closed
Open
Issue created Jun 22, 2020 by Cyril MARIN@cyril

[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.

https://git.frostnerd.com/PublicAndroidApps/DnsChanger/-/blob/master/app/src/main/java/com/frostnerd/dnschanger/activities/BackgroundVpnConfigureActivity.java#L56

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);
        }
    }
Assignee
Assign to
Time tracking