How to get a list of running applications using a fragment? The 2019 Stack Overflow Developer Survey Results Are In Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceIs there a way to run Python on Android?Why is the Android emulator so slow? How can we speed up the Android emulator?onActivityResult is not being called in FragmentfindViewById in Fragmenti want to add icon in listfragmnet (headlines fragment) in itCreate a TimePickerDialog using the FragmentDialog?How to link two xml pages in Android app when a button is clicked?Tabbed fragment don't show listviewsIssue with AutoCompleteTextView in a fragmnet used inside TabbedActivityfragment into other fragment

Intergalactic human space ship encounters another ship, character gets shunted off beyond known universe, reality starts collapsing

Make it rain characters

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

Would an alien lifeform be able to achieve space travel if lacking in vision?

How to determine omitted units in a publication

Python - Fishing Simulator

How to read αἱμύλιος or when to aspirate

Can a flute soloist sit?

Was credit for the black hole image misappropriated?

How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

Example of compact Riemannian manifold with only one geodesic.

Can the DM override racial traits?

Identify 80s or 90s comics with ripped creatures (not dwarves)

Keeping a retro style to sci-fi spaceships?

Deal with toxic manager when you can't quit

What other Star Trek series did the main TNG cast show up in?

Can we generate random numbers using irrational numbers like π and e?

Button changing its text & action. Good or terrible?

How to make Illustrator type tool selection automatically adapt with text length

Why can't wing-mounted spoilers be used to steepen approaches?

Why are PDP-7-style microprogrammed instructions out of vogue?

Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?

Mortgage adviser recommends a longer term than necessary combined with overpayments



How to get a list of running applications using a fragment?



The 2019 Stack Overflow Developer Survey Results Are In
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceIs there a way to run Python on Android?Why is the Android emulator so slow? How can we speed up the Android emulator?onActivityResult is not being called in FragmentfindViewById in Fragmenti want to add icon in listfragmnet (headlines fragment) in itCreate a TimePickerDialog using the FragmentDialog?How to link two xml pages in Android app when a button is clicked?Tabbed fragment don't show listviewsIssue with AutoCompleteTextView in a fragmnet used inside TabbedActivityfragment into other fragment



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have no idea how to do this inside a fragment. Most of the questions and answers here revolve around a normal activity (extends AppCompatActivity).



What I have is an application with a bottom navigation that uses fragments to switch screens. I tried my best to make things work but nothing works so I decided to ask for help here. I had different errors with different code blocks.



My goal is to get a list of running non-system applications and if possible, how many minutes / hours they were running.



import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

public class ListFragment extends Fragment
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
View view = inflater.inflate(R.layout.frag_list,null);
TextView tv1 = (TextView)view.findViewById(R.id.list1);
Intent mainIntent = new Intent(Intent.ACTION_MAIN,null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> pkgAppList = getActivity().getPackageManager().queryIntentActivities(mainIntent,0);
for(int i=0; i<pkgAppList.size(); i++)
System.out.println(pkgAppList.get(i).toString());

return view;




This is the last code I tried from around here. The way I understand this is that there are methods and classes used in the code blocks but aren't available for fragments (extends Fragment). What's a possible way around it?










share|improve this question






























    0















    I have no idea how to do this inside a fragment. Most of the questions and answers here revolve around a normal activity (extends AppCompatActivity).



    What I have is an application with a bottom navigation that uses fragments to switch screens. I tried my best to make things work but nothing works so I decided to ask for help here. I had different errors with different code blocks.



    My goal is to get a list of running non-system applications and if possible, how many minutes / hours they were running.



    import android.content.Intent;
    import android.content.pm.ResolveInfo;
    import android.os.Bundle;
    import android.support.annotation.NonNull;
    import android.support.annotation.Nullable;
    import android.support.v4.app.Fragment;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TextView;

    import java.util.List;

    public class ListFragment extends Fragment
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
    View view = inflater.inflate(R.layout.frag_list,null);
    TextView tv1 = (TextView)view.findViewById(R.id.list1);
    Intent mainIntent = new Intent(Intent.ACTION_MAIN,null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> pkgAppList = getActivity().getPackageManager().queryIntentActivities(mainIntent,0);
    for(int i=0; i<pkgAppList.size(); i++)
    System.out.println(pkgAppList.get(i).toString());

    return view;




    This is the last code I tried from around here. The way I understand this is that there are methods and classes used in the code blocks but aren't available for fragments (extends Fragment). What's a possible way around it?










    share|improve this question


























      0












      0








      0








      I have no idea how to do this inside a fragment. Most of the questions and answers here revolve around a normal activity (extends AppCompatActivity).



      What I have is an application with a bottom navigation that uses fragments to switch screens. I tried my best to make things work but nothing works so I decided to ask for help here. I had different errors with different code blocks.



      My goal is to get a list of running non-system applications and if possible, how many minutes / hours they were running.



      import android.content.Intent;
      import android.content.pm.ResolveInfo;
      import android.os.Bundle;
      import android.support.annotation.NonNull;
      import android.support.annotation.Nullable;
      import android.support.v4.app.Fragment;
      import android.util.Log;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.TextView;

      import java.util.List;

      public class ListFragment extends Fragment
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
      View view = inflater.inflate(R.layout.frag_list,null);
      TextView tv1 = (TextView)view.findViewById(R.id.list1);
      Intent mainIntent = new Intent(Intent.ACTION_MAIN,null);
      mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
      List<ResolveInfo> pkgAppList = getActivity().getPackageManager().queryIntentActivities(mainIntent,0);
      for(int i=0; i<pkgAppList.size(); i++)
      System.out.println(pkgAppList.get(i).toString());

      return view;




      This is the last code I tried from around here. The way I understand this is that there are methods and classes used in the code blocks but aren't available for fragments (extends Fragment). What's a possible way around it?










      share|improve this question
















      I have no idea how to do this inside a fragment. Most of the questions and answers here revolve around a normal activity (extends AppCompatActivity).



      What I have is an application with a bottom navigation that uses fragments to switch screens. I tried my best to make things work but nothing works so I decided to ask for help here. I had different errors with different code blocks.



      My goal is to get a list of running non-system applications and if possible, how many minutes / hours they were running.



      import android.content.Intent;
      import android.content.pm.ResolveInfo;
      import android.os.Bundle;
      import android.support.annotation.NonNull;
      import android.support.annotation.Nullable;
      import android.support.v4.app.Fragment;
      import android.util.Log;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.TextView;

      import java.util.List;

      public class ListFragment extends Fragment
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
      View view = inflater.inflate(R.layout.frag_list,null);
      TextView tv1 = (TextView)view.findViewById(R.id.list1);
      Intent mainIntent = new Intent(Intent.ACTION_MAIN,null);
      mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
      List<ResolveInfo> pkgAppList = getActivity().getPackageManager().queryIntentActivities(mainIntent,0);
      for(int i=0; i<pkgAppList.size(); i++)
      System.out.println(pkgAppList.get(i).toString());

      return view;




      This is the last code I tried from around here. The way I understand this is that there are methods and classes used in the code blocks but aren't available for fragments (extends Fragment). What's a possible way around it?







      android android-fragments






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 12:40









      Fantômas

      32.9k156491




      32.9k156491










      asked Mar 8 at 12:27









      Lancer26Lancer26

      33




      33






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You can do this :



          ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
          List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();

          for (int i = 0; i < runningAppProcessInfo.size(); i++)
          if(runningAppProcessInfo.get(i).processName.equals("com.the.app.you.are.looking.for"))
          // Do your stuff here.




          Hope it helps!






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063234%2fhow-to-get-a-list-of-running-applications-using-a-fragment%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can do this :



            ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
            List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();

            for (int i = 0; i < runningAppProcessInfo.size(); i++)
            if(runningAppProcessInfo.get(i).processName.equals("com.the.app.you.are.looking.for"))
            // Do your stuff here.




            Hope it helps!






            share|improve this answer



























              0














              You can do this :



              ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
              List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();

              for (int i = 0; i < runningAppProcessInfo.size(); i++)
              if(runningAppProcessInfo.get(i).processName.equals("com.the.app.you.are.looking.for"))
              // Do your stuff here.




              Hope it helps!






              share|improve this answer

























                0












                0








                0







                You can do this :



                ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
                List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();

                for (int i = 0; i < runningAppProcessInfo.size(); i++)
                if(runningAppProcessInfo.get(i).processName.equals("com.the.app.you.are.looking.for"))
                // Do your stuff here.




                Hope it helps!






                share|improve this answer













                You can do this :



                ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
                List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();

                for (int i = 0; i < runningAppProcessInfo.size(); i++)
                if(runningAppProcessInfo.get(i).processName.equals("com.the.app.you.are.looking.for"))
                // Do your stuff here.




                Hope it helps!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 8 at 12:51









                MaxouilleMaxouille

                1,5971928




                1,5971928





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063234%2fhow-to-get-a-list-of-running-applications-using-a-fragment%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                    Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                    Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved