1

I already has hashmap of apps usage. in details,a List of apps

//apps<Resolveinfo>
List<ResolveInfo> pkgAppsList = new ArrayList<ResolveInfo>();
PackageManager pm = this.getPackageManager();
pkgAppsList = pm.queryIntentActivities(mainIntent, 0);

and hashmap of popularity with package name as key string and usage as integer(number of user clicks on each app).

//hashmap<String,Integer>
public static HashMap listpopularity = new HashMap<String, Integer>();
listpopularity.put("com.example.app1",23)
listpopularity.put("com.example.app2",11)

what is best approach sort apps list according to package usages in hashmap. there may some apps that are not in hashmap usage because of user not clicked on app

hosein
  • 519
  • 5
  • 25
  • 1
    use comparable to sort the hashmap – SweetWisher ツ Apr 16 '14 at 04:54
  • hi usage in terms of what memory etc... – Ando Masahashi Apr 16 '14 at 04:55
  • possible duplicate of [How to Track App Usage in Android? How to detect when an activity is launched?](http://stackoverflow.com/questions/9012361/how-to-track-app-usage-in-android-how-to-detect-when-an-activity-is-launched) – Manish Dubey Apr 16 '14 at 05:05
  • @Manish Dubey: i know how track apps usage, i just want sort apps list , i saved user clicks on apps into hashmap as value and packagename as key, please read post carefully – hosein Apr 16 '14 at 05:47
  • @SweetWisher ツ: i don't want sort hashmap, i want sort apps list according usage that saved on hashmap with packagename as key and usage as value , i want send this sorted list to listview adapter – hosein Apr 16 '14 at 05:48
  • you need to sort the hashmap with values to get most number of user clicks for an app...then you can take the sorted list from the map using iterator... – Vamshi Apr 16 '14 at 06:22
  • @Vamshi: you said me use just one hashmap instead of a list of apps and hashmap of ? – hosein Apr 16 '14 at 06:33
  • If you have the value for each app clicks then one map is enough..let us assume you have 2 app...app1 with clicks 4 and app2 with clicks 5 , then you can put them in hashmap.put("app1", 4); hashmap.put("app2",5); so on....then you need to sort this map with values.... – Vamshi Apr 16 '14 at 06:42
  • once you are done with it post your code...i will let you know how to sort hashmap with values... – Vamshi Apr 16 '14 at 06:43
  • @Vamshi: no , sorry, i will post code in 2 hours,hashmap is like {"packagename1":4,"packagename1":2} and applist content list of app name , icon ,etc – hosein Apr 16 '14 at 07:43
  • @hosein: OK, post your code i will check.. – Vamshi Apr 16 '14 at 07:47
  • is there any relation between pkgAppsList and listpopularity? – Vamshi Apr 16 '14 at 11:23
  • @Vamshi: yes ,appinfo=pkgAppsList.get(3), appinfo.packagename is equal "com.example.app1" – hosein Apr 16 '14 at 14:58
  • @SweetWisher ツ: thanks for comparable keyword, i search and found what i want to do using comparable, i use comparable to sort apps not hashmap, update your comment as answer,please – hosein Apr 19 '14 at 05:34

1 Answers1

1

You need to use Comparable to sort the list....

a piece of code :

public class YourDataModel implements Comparable<YourDataModel> {
    @Override
        public int compareTo(YourDataModel o) {
            if (this.status.equals(o.status)) {
                return this.name.compareTo(o.name);
            } else {
                return this.status.compareTo(o.status);
            }
        }
}

Have a look here to get an idea to implement Comparable

Community
  • 1
  • 1
SweetWisher ツ
  • 7,296
  • 2
  • 30
  • 74