package com.frewen.ttplayer;
importjava.util.ArrayList;
importjava.util.LinkedList;
importjava.util.List;
importandroid.app.Activity;
importandroid.app.Application;
importandroid.content.Context;
importandroid.graphics.Bitmap;
importandroid.graphics.BitmapFactory;
importandroid.media.MediaPlayer;
importandroid.util.Log;
import com.frewen.ttplayer.entry.Music;
import com.frewen.ttplayer.entry.impl.Musicdata;
import com.frewen.ttplayer.util.MusicPreference;
public classMyApplication extends Application {
public static MediaPlayer mediaPlayer;
public static MusicPreferencemusicPreference;
public static ArrayList<Music> musics= new ArrayList<Music>();
public static boolean isStart = false;
public List<Activity> activityList =new LinkedList<Activity>();
public static Bitmap bitmap_l;
public static Bitmap bitmap_s;
public static MyApplication instance;
public ArrayList<Music> getMusics() {
return musics;
}
public static Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
new Thread(new Runnable() {
@Override
public void run() {
setMusics(Musicdata.getMultiDatas(context));
bitmap_l = BitmapFactory.decodeResource(context.getResources()??
R.drawable.default_bg_l);
bitmap_s =BitmapFactory.decodeResource(context.getResources()??
R.drawable.default_bg_s);
}
}).start();
mediaPlayer = new MediaPlayer();
musicPreference = new MusicPreference(context);
}
public void setMusics(ArrayList<Music>ms) {
musics.clear();
musics = ms;
Log.i("test"?? "?б????" + this.musics.size());
}
public MyApplication() {
}
// ???????л????MyApplication???
public static MyApplication getInstance() {
if (null == instance) {
instance = new MyApplication();
}
return instance;
}
// ???Activity????????
public void addActivity(Activity activity) {
activityList.add(activity);
}
// ????????Activity??finish
public void exit() {
for (Activity activity : activityList) {
activity.finish();
}
System.exit(0);
}
/**
* ??musics????????????miusic???
*
*@param musics
*/
public void append(ArrayList<Music>musics) {
if (musics != null) {
this.musics.addAll(musics);
}
}
public void append(Music music) {
if (music != null) {
this.musics.add(music);
}
}
}

????android????????????????????????Application??????????????????????Application?????????? (singleton)?????????.application????????????????????????г???????????????????????????????????????????????????????????????Activity??Service?л???????????????????????Application???????Щ????????????????????????????????