logo
down
shadow

How to get running application activity Name in android 5.0(L)?


How to get running application activity Name in android 5.0(L)?

By : user2948390
Date : November 14 2020, 04:51 PM
will be helpful for those in need Prior to Android L your code will work, but from Android L onward getRunningTask will not work. You have to use getAppRunningProcess.
Check this code below -
code :
public class DetectCalendarLaunchRunnable implements Runnable {

@Override
public void run() {
  String[] activePackages;
  if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
    activePackages = getActivePackages();
  } else {
    activePackages = getActivePackagesCompat();
  }
  if (activePackages != null) {
    for (String activePackage : activePackages) {
      if (activePackage.equals("com.google.android.calendar")) {
        //Calendar app is launched, do something
      }
    }
  }
  mHandler.postDelayed(this, 1000);
}

String[] getActivePackagesCompat() {
  final List<ActivityManager.RunningTaskInfo> taskInfo = mActivityManager.getRunningTasks(1);
  final ComponentName componentName = taskInfo.get(0).topActivity;
  final String[] activePackages = new String[1];
  activePackages[0] = componentName.getPackageName();
  return activePackages;
}

String[] getActivePackages() {
  final Set<String> activePackages = new HashSet<String>();
  final List<ActivityManager.RunningAppProcessInfo> processInfos = mActivityManager.getRunningAppProcesses();
  for (ActivityManager.RunningAppProcessInfo processInfo : processInfos) {
    if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
      activePackages.addAll(Arrays.asList(processInfo.pkgList));
    }
  }
  return activePackages.toArray(new String[activePackages.size()]);
}
}  


Share : facebook icon twitter icon
Launching activity from another application not displaying the activity, but it is running

Launching activity from another application not displaying the activity, but it is running


By : IvanI
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further It bounces back means the plugin activity has some problem in launching.
IntelliJ IDEA running Android Native Activity application

IntelliJ IDEA running Android Native Activity application


By : user3743834
Date : March 29 2020, 07:55 AM
this one helps. I'm afraid there is no support for launching NDK Activity right now, please submit a feature request.
Converting normal Android activity application to tabbed activity application

Converting normal Android activity application to tabbed activity application


By : Jaap de Jong
Date : March 29 2020, 07:55 AM
hope this fix your issue You will need to use the Fragments API introduced in API Level 11. To get started with check out this example on Android Blog. (http://android-developers.blogspot.in/2011/02/android-30-fragments-api.html)
Can I be sure that Android application finished running by checking isFinish() in the main Activity's onPause()?

Can I be sure that Android application finished running by checking isFinish() in the main Activity's onPause()?


By : Alisha
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I think you need to rethink your design because it seems that it isFinishing is true only when finish is called on the activity and does not account for cases where the activity is destroyed because of low memory.
From the docs:
Get current running Activity in Android through <application> tag class

Get current running Activity in Android through <application> tag class


By : Siyada Ibrahim
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You can create an Android Service and print the current activity from there. For instance, the following service will run indefinitely with a 0.7 second timeout and print the current activity to LogCat:
code :
public class MyService extends Service {

public static final String TAG = "Background Service";

public boolean wait;
public boolean stop = false;

SharedPreferences prefs;

@Override
public IBinder onBind(Intent intent) {
    Log.i(TAG, "On bind of service");
    return null;
}

@Override
public void onDestroy() {
    stop = true;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    (new Thread(new Runnable() {

        public void run() {
            try {
                update();
                return;
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }

    })).start();

    return super.onStartCommand(intent, flags, startId);
}

public void update() {
    List list;
    String str;

    do {
        try {
            Thread.sleep(701L);
        } catch (InterruptedException interruptedexception) {
            interruptedexception.printStackTrace();
        }

        list = ((ActivityManager) getSystemService("activity"))
                .getRunningTasks(1);
        str = ((android.app.ActivityManager.RunningTaskInfo) list.get(0)).topActivity
                .getClassName();

        Log.d(TAG, str);
    } while (!stop);

    stopSelf();
}
}
Intent intent = new Intent(this, MyService.class);
startService(intent);
stopService(intent);
Related Posts Related Posts :
  • Unable to add column dynamically into the sqlite table
  • android persistence activity which never stop
  • The Google Play services resources were not found. Check your project configuration to ensure that the resources are inc
  • How to select files from google drive in android?
  • Run a AsyncTask every 10 seconds until cancelled
  • Blur on touch. Android application
  • NDK Android - Can't build ARMv5 and V7 at the same time
  • Android development with Eclipse clean and build
  • How to set Different Key Background for every Key in Android Custom Keyboard
  • Face recognition using OpenCV in android?
  • Tumblr API - Jumblr for Android [OAuthConnectionException]
  • Small Icon on Notification not working correctly
  • ConstraintLayout match parent height on larger screens but scroll on smaller
  • Kotlin version issue
  • How can i make my android app look the same on RTL and LTR languages?
  • Can not detect Android NDK toolchain
  • Falling back on PROMPT mode since _cordovaNative is missing. Expected for Android 3.2 and lower only.
  • Facebook Key Hash for Play Store Release
  • backbutton confirm exit app android + phonegap + jquery
  • How to Make Instagram Listview in android?
  • Up and Down Enemy Movement using translate corona sdk
  • Set selection method is not working in gallery in android
  • How to implement onOptionsItemSelected for Sub-Menu Items?
  • HttpHostConnectException connection refused ConnectException ErrnoException
  • Adding Buttons to expendableListView as last Child
  • Android. Block phone on startup
  • How to programmatically check If string is not to wide to fit onto the screen in Android
  • EditText box cursor appear after touching box?
  • using if statement when video is done playing
  • Add to Aspectpath not found MonkeyTalk
  • GooglePlusUtil cannot be resolved (Android)
  • Trouble understanding Relative Layout
  • How to title/name each fragment separately to appear on PagerTitleStrip?
  • Android webView blinks
  • Available service types in WifiP2pDnsSdServiceInfo.newInstance
  • Hide only bottom action bar Android
  • Android + MoPub + PhoneGap (Cordova) Integration (Half working)
  • Android OnTouchListener results in jerky drags
  • android notification disappears after reboot
  • Optimising Canny Edge Detector for Android
  • How to Play the online streaming radio in Android
  • Blurry map tiles at start of android app based on google Maps API v2
  • How to combine java native within the XML android and dart Flutter
  • Intercept the outgoing call data, alter it & then write it back out- Why it is not possible?- Android
  • Bundle extra sends wrong string
  • Display a view using windowmanager on lock screen
  • is it possible to load images from the directory on web server?
  • android SDK manager, only show installed package
  • How to handle time zone difference between server and native android application?
  • ViewPager PagerAdapter delete items
  • How to solve different Preview/Picture sizes returned by android.hardware.camera?
  • How to get songs from album/Artist in android,using MediametadataRetriever?
  • Android UIAutomator how to tilt device
  • DialogFragment issues with screen orientation and MediaController
  • blank screen after re-starting launcher activity (failed binder transaction)
  • How to start activity Language and input
  • location-based Augmented Reality Framework (Android, iOS) with 3D Models?
  • android teamviewer intent with parameters
  • Picasso does not call onBitmapLoaded for the first time
  • How can I pass an audio file as input instead of recorded voice to Google search voice?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org