Android应用程序安装但未启动

时间:2015-11-19 13:08:46

标签: java android

在Android Studio 1.4上运行一个应用程序,到目前为止: - 任何地方都没有红色下划线 - Build-> Clean Project运行正常 - Build-> Generate Singed APK运行良好

尝试将.apk安装到两个不同的手机中,它安装时没有任何警告,但之后它确实启动了。

MainActivity.java

package application.newsjunkygr;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.Toast;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private WebView mWebView;

    ListView lv;
    ArrayList<Planet> planetList;
    UrlAdapter plAdapter;

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

        this.setContentView(2130903064);
        this.lv = (ListView)this.findViewById(2131034172);
        this.displayPlanetList();

        setContentView(R.layout.activity_main);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mWebView = (WebView) findViewById(R.id.content_main_webview);
        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

    }

    private void displayPlanetList() {
        this.planetList = new ArrayList();
        this.planetList.add(new Planet("Mercury", 57000000));
        this.planetList.add(new Planet("Venus", 23700000));
        this.planetList.add(new Planet("Mars", 35000000));
        this.planetList.add(new Planet("Jupiter", 5000000));
        this.planetList.add(new Planet("Saturn", 746000000));
        this.plAdapter = new UrlAdapter(this.planetList, this);
        this.lv.setAdapter(this.plAdapter);
    }

    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        int pos = this.lv.getPositionForView(buttonView);
        if(pos != -1) {
            Planet p = (Planet)this.planetList.get(pos);
            p.setSelected(isChecked);
            Toast.makeText(this, "Clicked on Planet: " + p.getName() + ". State: is " + isChecked, 0).show();
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="application.newsjunkygr" >

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

0 个答案:

没有答案