Skip to content Skip to sidebar Skip to footer

How Do I Compare Values Against My Database?

In my application, I'm inserting the user visit apps package name from Google Play and save it in a database. I display only that apps from install apps that package name are in

Solution 1:

First of: don't use non-generic Lists.

In your loadInstalledApps method, you use this line:

Listarraylist= db.getAllApps();

As the getAllApps returns an ArrayList<String> your List should be of type List<String>.

Second: You can't compare items in a list like what you're trying to do:

if(arraylist.equals(p.packageName)

You're essentially trying to see if the ArrayList object is equal to a String. Comparing apples with oranges doesn't go well either...

Third: Comparing in code instead of comparing in SQL is really slow performancewise and should definately be avoided, especially on mobile OS's, as this is a waste of memory and CPU.

If you really want to compare in code, you can do it like this:

if(arraylist.contains(p.packageName)) {
    // Do somethingAppapp=newApp();
    app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
    app.setPackageName(p.packageName);
    app.setVersionName(p.versionName);
    app.setVersionCode(p.versionCode);
    CharSequencedescription= p.applicationInfo.loadDescription(packageManager);
    app.setDescription(description != null ? 
    description.toString() : "");
    apps.add(app);
}

But I wouldn't recommend this path.

Post a Comment for "How Do I Compare Values Against My Database?"