3

I want to know the Recent launch time of an application in android?

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
raj
  • 743
  • 6
  • 21
  • Refer here : http://stackoverflow.com/questions/2324847/launch-time-of-an-app – Pankaj Kumar Nov 08 '11 at 05:31
  • Dear go through this StackOverflow FAQ first: http://stackoverflow.com/faq#dontask – Paresh Mayani Nov 10 '11 at 09:54
  • Dear don't ask redundant question otherwise community will flag it or vote for close this kind of question. – Paresh Mayani Nov 10 '11 at 09:56
  • 1
    Asking duplicate questions is not welcome behaviour here. If you aren't getting any good answers then please edit your question to add more information or place a bounty. – Kev Nov 10 '11 at 11:22

2 Answers2

1

You can Log the System time in the onCreate of the Main Activity of the application. This time can be then set in a class level field and accessed from elsewhere in the application. You could also have similar variable for onResume(..) etc

public class MainActivity extends Activity { 
    long launchTime;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        launchTime = System.currentTimeMillis();
        ....
    }
}
Rajdeep Dua
  • 11,190
  • 2
  • 32
  • 22
  • i want to know the recent launch of other apps from my application.can it is possible? – raj Nov 08 '11 at 09:22
0

The best you can do is create a STICKY Service that tracks all of the running application.

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

    Timer timer  =  new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {

        public void run() 
        {
            final ActivityManager activityManager  =  (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
            final List<RunningTaskInfo> services  =  activityManager.getRunningTasks(Integer.MAX_VALUE);
                 for (int i = 0; i < services.size(); i++) {
                     if(!stalkList.contains(services.get(i).baseActivity.getPackageName()))
                     {
                          // you may store the time here  
                          stalkList.add(services.get(i).baseActivity.getPackageName());
                     }
                }

                 List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
                for(int i = 0; i < procInfos.size(); i++) {  

                    ArrayList<String> runningPkgs = new ArrayList<String>(Arrays.asList(procInfos.get(i).pkgList));

                    Collection diff = subtractSets(runningPkgs, stalkList); 

                    if(diff != null)
                    {
                        stalkList.removeAll(diff);
                    }
               }


        }
    }, 20000, 6000);  // every 6 seconds


    return START_STICKY;
}
Reno
  • 33,594
  • 11
  • 89
  • 102