【发布时间】:2019-07-07 20:38:01
【问题描述】:
在我的片段中,我从另一个类调用静态方法
if (getActivity() != null) {
Main.bindMusicService(getActivity().getApplicationContext(), position, songList);
}
主类:
private static Context context;
private static ArrayList<Song> songList;
private static int songIndex;
public static void bindMusicService(Context c, int songPos, ArrayList<Song> songs){
context = c;
songIndex = songPos;
songList = songs;
/*mediaPlayerServiceIntent binds our connection to the MediaPlayerService. */
if (!mServiceIsBound) {
try {
mediaPlayerServiceIntent = new Intent(c, MediaPlayerService.class);
c.bindService(mediaPlayerServiceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
} catch (Exception e) {
Log.e("Main", "Service is not bound!");
}
}else{
Main.mediaPlayerService.startActionPlay(context, songList, songIndex);
}
Log.i("Main","Service is bound!");
}
我收到此上下文警告
Do not place Android context classes in static fields; this is a memory leak
将我的数组列表、适配器位置和上下文发送到另一个类中的另一个方法的正确方法是什么?
【问题讨论】:
标签: java android static-methods android-context