Emad-ud-deen
Emad-ud-deen

Reputation: 4864

Execute a method in an activity from a widget?

Is it possible to call a particular method that's in an Activity from a widget?

This is the method I would like to call:

/*
 * Close out this screen.
 */
private void finishThisActivity() {
    this.finish();
} // End method finishThisActivity.

If this can be done, can you show some sample code?

Upvotes: 0

Views: 209

Answers (1)

Ranjit Mishra
Ranjit Mishra

Reputation: 450

i will like to share my idea that if you want to call your own method finishThisActivity() from widget then you need to use a tag called "android:onclick="methodname".For you the method name should be "finishThisActivity".

EXAMPLE: Suppose you want to call this method in place of onClick() in case of Button then you need to use the above tag for button and you need to put the corresponding method

private void finishThisActivity() {

this.finish();

}

outside of onCreate()

Upvotes: 1

Related Questions