1
//. . .

public class MainActivity extends Activity {

    //. . .

    @Override
    protected void onCreate( Bundle savedInstanceState ) {
        //. . .
        mainActivityProcedure ( );
    }

    //. . .

    public static void mainActivityProcedure ( ) {
        //. . .
        AnotherActivity.anotherActivityProcedure ( ) ;
        SomeActivity.someActivityProcedure ( );
        //. . .
    }

    //. . .

}

//. . .

public class SomeActivity extends Activity {

    //. . .

    @Override
    protected void onCreate( Bundle savedInstanceState ) {
        //. . .
        someWebView = ( WebView ) findViewById ( R.id.someWebView );
        //. . .
    }

    //. . .

    public static void someActivityProcedure ( ) {
        //. . .
        try {
            someWebView.loadDataWithBaseURL ( null , someHTMLCode, mimeType, encoding, null );
    catch ( Exception e ) {
        Log.i("SomeActivity", "someWebView loadDataBaseURL () " + e.toString() );
    }
        //. . .
    }

    //. . .
}

//. . .

public class AnotherActivity extends Activity {

    //. . .

    @Override
    protected void onCreate ( Bundle savedInstanceState ) {
        //. . .
        anotherWebView = ( WebView ) findViewById ( R . id.anotherWebView ) ;
        //. . .
    }

    //. . .

    public static void anotherActivityProcedure ( ) {
        //. . .
        anotherWebView . loadDataWithBaseURL ( null, anotherHTMLCode, mimeType, encoding, null ) ;
        //. . .
    }
}

当 anotherActivityProcedure 调用时,AnotherActivity 总是加载 anotherHTMLCode。SomeActivity 加载 someHTMLCode,除非从 MainActivity.onCreate 调用 mainActivityProcedure。someWebView 或 SomeActivity 有什么问题?我不能把原始代码放在这里。

补充:在 loadDataWithBaseURL() 中替换 null 不能修复它。另外:Logcat 显示消息 java.lang.NullPointerException 将 Log.i() 从 catch 中放置。

4

1 回答 1

0

Try this, Initilized SomeActivity inside MainActivity and the use _someactivity object you can access.

SomeActivity _someactivity = new SomeActivity();
_someactivity.someActivityProcedure ();
于 2013-03-11T04:46:56.187 回答