我有 2 个活动调用 1 个活动,例如
Activity 1
Activity a
Activity 2
Activity a
我想从 Activity a 返回到它被调用的任何活动。
目前我收到空指针异常,说活动 a 没有定义父活动。
活动一和二如下
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TextView urlTv = (TextView) view.findViewById(R.id.url);
// String url = urlTv.getText().toString();
String url = projectsList.get(position).get("url");
//Intent intent = new Intent(Intent.ACTION_VIEW);
Intent intent = new Intent(getApplicationContext(), LaunchReadMoreActivity.class);
intent.putExtra("url", url);
//intent.setData(Uri.parse(url));
startActivity(intent);
}
});
活动 A:公共类 LaunchReadMoreActivity 扩展 Activity{
WebView myWebView;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.read_screen);
Intent intent = getIntent();
String url = intent.getStringExtra("url");
WebView myWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
//webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
myWebView.setScrollbarFadingEnabled(false);
try {
// load the url
myWebView.loadUrl(url);
} catch (Exception e) {
e.printStackTrace();
}
// //myWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
// myWebView.setInitialScale(50);
// //myWebView.loadUrl(url);
// myWebView.loadUrl(url);
//
setupActionBar();
}
setupActionBar();