开发者

"Calling" UI activity method from a class

I have an Activity which mainly handles the UI, and I do most of the rest from another class (not a service). One o开发者_C百科f the things I do from that class is playing audio. What I need to do is tell my Activity when the audio finished playing (OnCompletionListener).

public class MyClass implements OnCompletionListener {
          private MyActivity activity = new MyActivity();
public MyClass(){
}
 ...........
 ...........
 ...........
@Override
    public void onCompletion(MediaPlayer mp) {
        activity.onComplete();

    }

}

This is wrong because "Cannot make a static reference to the non-static method onComplete() from the type MyActivity.

I'm pretty sure I'm using Java wrong, but I cant figure out how to call onComplete from the class. (changing onComplete to static isn't posible).

EDIT: added a constructor to MyActivity:

public MyActivity(){

    }

and created an instance of MyActivity, activity (see the edited code above), passed it to the method, but when I do activity.onComplete(); it stops unexpectedly. (I dont know why my logcat isnt working, I'll post back when I get it to work)


Just pass an instance of MyActivity to MyClass and call a method on it. It's arguable approach but best I can suggest having information that you provided.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜