2017-07-08 180 views
0

此Android项目是关于Webview的。 当它点击一个叫做goURL的按钮时它开始活动。 但是当应用程序启动时可以启动一些活动吗?(不是来自按钮的活动)。 我的猜测是装上去上的onCreate启动应用程序时的Android启动活动

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 


} 


public void goURL(View view){ 
    TextView tvURL = (TextView)findViewById(R.id.txtURL); 
    String url = tvURL.getText().toString(); 
    Log.i("URL", "Opening URL with WebView :" + url); 

    final long startTime = System.currentTimeMillis(); 
    WebView webView = (WebView)findViewById(R.id.webView); 

//webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 


webView.loadUrl(url); 

我的猜测是,创建有关视图的意图。 但不知道如何去做

+0

是的,你可以直接把你的代码放在'onCreate()'方法而不是'view'点击方​​法中。 – Shailesh

回答

0

您可以在您的Manifest.xml(或Android Studio)中定义哪些活动是您的MainActivity,然后首先打开MainActivity,然后调用onCreate方法。

0

你可以直接把代码放在onCreate()函数中。

0

启动活动调用这onCreate

Intent intent = new Intent(this, SecondActivity.class); 
startActivity(intent); 

和清单application

设置活动
<activity android:name=".SecondActivity" /> 
0
  1. 找到从Manifest.xml启动应用程序时显示给用户的第一个活动。
  2. 在该活动的onCreate()方法中添加:里面的onCreate()

    TextView tvURL = (TextView)findViewById(R.id.txtURL); 
    String url = tvURL.getText().toString(); 
    Log.i("URL", "Opening URL with WebView :" + url); 
    final long startTime = System.currentTimeMillis(); 
    WebView webView = (WebView)findViewById(R.id.webView); 
    //webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 
    webView.loadUrl(url); 
    
  3. 使用意图,如果要启动您的活动

  4. 否则,你可以做任何活动作为原料的活性你应用程序通过在Manifest.xml中使用intent-filter标记。
相关问题