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;
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
add a comment |
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
add a comment |
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
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
android android-fragments
edited Mar 8 at 12:40
Fantômas
32.9k156491
32.9k156491
asked Mar 8 at 12:27
Lancer26Lancer26
33
33
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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!
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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!
add a comment |
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!
add a comment |
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!
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!
answered Mar 8 at 12:51
MaxouilleMaxouille
1,5971928
1,5971928
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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