Reputation: 126
I have this code and I want to access this from another class:
public void nomorA(int num){
try {
am = ctx.getAssets();
AssetFileDescriptor afd = am.openFd("nom.wav");
player = new MediaPlayer();
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
player.prepare();
player.start();
player.setLooping(false);
Thread.sleep(1000);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
How do I call this method from Main Activity
and pass its context to the called method?
Upvotes: 0
Views: 621
Reputation: 12664
add Context as second parameter and make static function
public class Utility{
public static void nomorA(int num,Context ctx){
}
}
Call function :
Utility. nomorA(1,ClassName.this);
Upvotes: 1