Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am calling from activityA a method that is on activityB. Method is called from A to B properly but when I execute inside it webviewB.loadUrl(myUrl), app crashes for a nullpointerexception. Same webviewB method, if executed from activityB, works properly. Probably is done because context, when calling from A to B must be set, but how? Which is the best way to do it? Thank you.

ActivityA (tabHost) and ActivityB (tabcontent) are initialized properly and webview from ActivityB shows URL1. Then when evet from ActivityA is recived, I need to load URL2 on webview from ActivityB.

EDIT: when event is received on ActivityA,

 ActivityB test = new ActivityB();
 test.recalcula();

ActivityB,

@Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        setContentView(R.layout.vistaaib); 

        webviewB = (WebView) findViewById(R.id.webviewB);


            webviewB.loadUrl(URL1);

...


public void recalcula (){


        webviewB.loadUrl(URL2);

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
155 views
Welcome To Ask or Share your Answers For Others

1 Answer

Either intents as suggested by Ortisi. Or Why don't you try creating a class, create that method in this class, And call that method from both the activity.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...