Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7603751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:44:03+00:00 2026-05-30T23:44:03+00:00

In my app I have a system where I am able to show dialogs

  • 0

In my app I have a system where I am able to show dialogs from anywhere in the app, even from secondary threads.When I receive some notifications from the server, I just bring the dialog in front of user eyes(the dialog is shown in a transparent activity opened from the application context). My problem is that when the app is in background and receives signals from the server, it starts the transparent activity containing the dialog, so the app comes in foreground – which is against android(and my) rules.

I created a notification system so the incomings from server are shown is the status bar.
I associated with the notification the transparent activity(which holds the dialog), so when the user click on the notification, will be brought to the dialog.

Intent notificationIntent = new Intent(CVSApplication.getInstance(), CVSDialogActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(CVSApplication.getInstance(), 0, notificationIntent, 0);

The problem is the application is anyway brought to front, even if the user do not click on the notification.

Is there any way to prevent CVSDialogActivity from returning from backgound when startActivity is called?
Here is the intent which starts the CVSDialogActivity:

intent = new Intent(app, CVSDialogActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(USE_CUSTOM_CONTENT, false);
intent.putExtra(INSTANCE, this.hashCode());

I also tried this variant:

intent = new Intent(app, CVSDialogActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
      .addFlags(Intent.FLAG_FROM_BACKGROUND);
intent.putExtra(USE_CUSTOM_CONTENT, false);
intent.putExtra(INSTANCE, this.hashCode());

,but when startActivity(intent) is called the app is brought to front.(I want to show the activity containing the dialog, but in background, and when the user click on the notification, to bring the app to foreground).

Thanks,
Alex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:44:05+00:00Added an answer on May 30, 2026 at 11:44 pm

    I’ve found a way to resolve this. I created a system which tell me if the app is in background or not(using running processes) like this:

    public boolean isInBackground(){
        ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> appProcesses= activityManager.getRunningAppProcesses();     
    
    
        for (RunningAppProcessInfo appProcess : appProcesses) {
    
            PackageInfo p = null;
            try {
                p = this.getPackageManager().getPackageInfo(appProcess.pkgList[0], PackageManager.GET_PERMISSIONS);
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
    
    
    
            if(p != null && p.packageName.equals(getPackageName()) && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND){                                
                System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!Is in background: false");
                return false;
            }
        }
    
        System.out.println("!!!!!!!!!!!!!!!!!!!!!Is in background: true");
        return true;
    }
    

    Now if I am in background, I will not start the dialog, I will start only the notification, and when the notification is pressed, the application is brought to the front and the dialog is shown to the user.

    Alex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a the following server side app.config for a WCF service: <system.serviceModel> <bindings>
Let's say you have an app that declares itself able to handle a system
Some Background I have an iPhone app with three UIWebViews, each used to show
I'm creating a WPF app and have a system tray icon with a context
I have an App that will send authenticated emails using System.Net.Mail and System.Net.NetworkCredential my
I have a 'template' system in my CMS rails app. Basically the whole HTML
I have a C# app which uses a System.Diagnostics.Process to run another exe. I
I have a PHP app running happily on the following system: web app: PHP
I have a C# app that subscribes to a topic on our messaging system
I have an asp.net app that uses System.IO.Path.GetTempFileName() for temporary files. In the production

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.