dimanche 11 janvier 2015

Performance Issue When starting Android Music Player Activity During database population

I am writing an application where the database gets created and as soon as 1 insertion in database takes place, the startActivity() API is getting called in a different thread. The startActivity() gets called instantly, but it takes a lot of time for the the onCreate of that activity get called. Following is the code where I am starting the activity :



void startPopulatingDb(String[] list) {

if(list == null)
return;

openDB();
MetaDataRetriever mdr = new MetaDataRetriever();

for(int i = 0; i < list.length; i++) {
ContentValues values = new ContentValues();
String media;

media = devicePath+"/"+list[i];
//Log.d("SOURAV", media);
MetaData entry = mdr.getMetaData(media);

if(entry != null) {
values.put(MusicEntry.COLUMN_NAME_TITLE, entry.getTitle());
values.put(MusicEntry.COLUMN_NAME_ARTIST, entry.getArtist());
values.put(MusicEntry.COLUMN_NAME_ALBUM, entry.getAlbum());
values.put(MusicEntry.COLUMN_NAME_GENRE, entry.getGenre());
values.put(MusicEntry.COLUMN_NAME_URI, entry.getUri().toString());

database.insert(MusicEntry.TABLE_NAME, "unknown", values);
getApplicationContext().getContentResolver().notifyChange(
MusicPlayerSQLiteHelper.DB_URI, null);

if(mediaCount == 1) {
Thread thread = new Thread() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent startIntent = new Intent(getApplicationContext(), MainActivity.class);
startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.w("MusicPalyer", "LaunchOrKillService::Starting Activity");

startActivity(startIntent);
}
};
thread.start();
}
Intent dataSetChangeIntent = new Intent();
dataSetChangeIntent.setAction(MODIFY_DATA_SET);
sendBroadcast(dataSetChangeIntent);

mediaCount++;
} else {
mediaCount = 0;
}
}
}


Any ideas why there is so lag in launching activity ? Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire