更改了应用程序的启动活动,现在应用程序无法启动

时间:2016-10-19 05:06:44

标签: android android-activity android-manifest

我正在处理一个包含5个左右活动的应用,我尝试将我的启动器活动从MapsActivity更改为MainActivity。我一直有MapsActivity,但今天我添加了MainActivity并简单地交换了MapsActiviy和MainActivity的android:name属性。突然间,我的应用程序无法打开。如果我试图运行该应用程序,我会看到该图标出现在Nexus 6P和HTC One M7上,但点击图标后,没有任何反应。我所做的就是改变清单FROM:

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

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

    ............
    Skips Several Lines
    ............

    <activity
        android:name=".ChatActivity"
        android:screenOrientation="portrait" />
    <activity android:name=".MainActivity"/>
    <activity android:name=".TotalsListViewActivity" />
    <activity android:name=".PlacesListViewActivity" />
</application>

TO:

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

<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">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

   ............
    Skips Several Lines
    ............

    <activity
        android:name=".ChatActivity"
        android:screenOrientation="portrait" />
    <activity android:name=".MapsActivity"/>
    <activity android:name=".TotalsListViewActivity" />
    <activity android:name=".PlacesListViewActivity" />
</application>

我阅读了一些帖子,例如https://stackoverflow.com/a/3632061/4937741,关于如何更改清单可能不足以让Android Studio更改其应用的运行配置。所有帖子似乎都说要去Run&gt;编辑配置并确保将新的默认启动器活动设置为运行而不是旧的启动器活动。在我的情况下,它始终设置为运行默认活动:

Editing Configurations

我已尝试将其更改为明确运行MainActivity,但这并没有帮助。我甚至尝试删除MapsActivity,但这并没有帮助。 LogCat似乎没有显示任何错误:

   10-19 00:48:04.383 20349-20407/? D/ClClient: Not sending keepalive.  Current connection state=STOPPED

                                             --------- beginning of system
10-19 00:48:05.075 914-3870/? I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.artfara.apps.kipper/.MainActivity (has extras)} from uid 10029 on display 0
10-19 00:48:05.077 513-2908/? D/audio_hw_primary: out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
10-19 00:48:05.091 513-2908/? D/audio_hw_primary: select_devices: out_snd_device(2: speaker) in_snd_device(0: none)
10-19 00:48:05.091 513-2908/? D/msm8974_platform: platform_send_audio_calibration: sending audio calibration for snd_device(2) acdb_id(15)
10-19 00:48:05.092 513-2908/? I/soundtrigger: audio_extn_sound_trigger_update_device_status: device 0x2 of type 0 for Event 1
10-19 00:48:05.105 513-2908/? D/audio_hw_primary: enable_snd_device: snd_device(2: speaker)
10-19 00:48:05.109 513-2908/? D/audio_hw_primary: enable_audio_route: apply and update mixer path: low-latency-playback speaker
10-19 00:48:05.132 1350-1350/? I/GrantPermissionsActivity: No package: null
                                                           android.content.pm.PackageManager$NameNotFoundException
                                                               at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:137)
                                                               at com.android.packageinstaller.permission.ui.GrantPermissionsActivity.getCallingPackageInfo(GrantPermissionsActivity.java:335)
                                                               at com.android.packageinstaller.permission.ui.GrantPermissionsActivity.onCreate(GrantPermissionsActivity.java:100)
                                                               at android.app.Activity.performCreate(Activity.java:6251)
                                                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                               at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                               at android.os.Handler.dispatchMessage(Handler.java:102)
                                                               at android.os.Looper.loop(Looper.java:148)
                                                               at android.app.ActivityThread.main(ActivityThread.java:5422)
                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-19 00:48:05.141 914-3581/? W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2335ed6 attribute=null, token = android.os.BinderProxy@182e308
10-19 00:48:05.637 513-2908/? D/audio_hw_primary: disable_audio_route: reset and update mixer path: low-latency-playback speaker
10-19 00:48:05.639 513-2908/? D/audio_hw_primary: disable_snd_device: snd_device(2: speaker)
10-19 00:48:05.654 513-2908/? I/soundtrigger: audio_extn_sound_trigger_update_device_status: device 0x2 of type 0 for Event 0
10-19 00:48:05.932 914-3870/? D/WifiService: acquireWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@4c604e5}
10-19 00:48:05.986 914-3912/? D/WifiService: releaseWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@4c604e5}
10-19 00:48:06.011 3315-3315/? I/wpa_supplicant: wlan0: WPA: Group rekeying completed with f0:b2:e5:bd:99:c0 [GTK=CCMP]
10-19 00:48:06.012 914-3106/? D/IpReachabilityMonitor: probing ip=10.31.112.1%5
10-19 00:48:06.038 19446-19453/? E/DataBuffer: Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@7858ede)
10-19 00:48:07.091 914-3121/? D/ConnectivityService: notifyType CAP_CHANGED for NetworkAgentInfo [WIFI () - 168]
10-19 00:48:07.105 914-3121/? D/ConnectivityService: updateNetworkScore for NetworkAgentInfo [WIFI () - 168] to 56
10-19 00:48:08.712 668-701/? I/Finsky: [1983] com.google.android.finsky.c.e.run(2152): Replicating app states via AMAS.
10-19 00:48:08.744 914-3261/? I/sensors: batch
10-19 00:48:08.744 914-3261/? I/sensors: activate
10-19 00:48:08.742 4376-4376/? W/Binder_C: type=1400 audit(0.0:141173): avc: denied { ioctl } for path="socket:[1339276]" dev="sockfs" ino=1339276 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0
10-19 00:48:08.742 4376-4376/? W/Binder_C: type=1400 audit(0.0:141174): avc: denied { ioctl } for path="socket:[1339276]" dev="sockfs" ino=1339276 ioctlcmd=7704 scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=unix_stream_socket permissive=0
10-19 00:48:08.753 914-3039/? I/hubconnection: sensorhub said: 'batch 4 flags:0, sampling_rate_Hz:10.00, max_report_latency_us:0'
10-19 00:48:08.753 914-3039/? I/hubconnection: sensorhub said: 'activate 4 enable:1'
10-19 00:48:08.876 668-701/? I/Finsky: [1983] com.google.android.finsky.c.c.a(314): Completed 0 account content syncs with 0 successful.
10-19 00:48:08.878 668-668/? I/Finsky: [1] com.google.android.finsky.services.j.a(148): Installation state replication succeeded.
10-19 00:48:08.896 19619-19625/? W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
10-19 00:48:08.897 19619-19625/? W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
10-19 00:48:08.897 19619-19625/? W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
10-19 00:48:09.061 914-3581/? I/sensors: activate
10-19 00:48:09.064 914-3039/? I/hubconnection: sensorhub said: 'activate 4 enable:0'
10-19 00:48:09.426 14682-14682/? I/ServiceManager: Waiting for service AtCmdFwd...
10-19 00:48:10.427 14682-14682/? I/ServiceManager: Waiting for service AtCmdFwd...
10-19 00:48:11.429 14682-14682/? I/ServiceManager: Waiting for service AtCmdFwd...
10-19 00:48:12.430 14682-14682/? I/ServiceManager: Waiting for service AtCmdFwd...
10-19 00:48:13.432 14682-14682/? I/ServiceManager: Waiting for service AtCmdFwd...
10-19 00:48:14.383 20349-20407/? D/ClClient: Not sending keepalive.  Current connection state=STOPPED
10-19 00:48:14.433 14682-14682/? W/Atfwd_Sendcmd: AtCmdFwd service not published, waiting... retryCnt : 3
10-19 00:48:17.418 24712-14857/? D/com.gsamlabs.bbm.lib.NotifyingService: ===:56:3930:28.5:2
10-19 00:48:21.824 914-7312/? D/NetlinkSocketObserver: NeighborEvent{elapsedMs=82913527, 10.31.112.1, [0026980A93C1], RTM_NEWNEIGH, NUD_STALE}
10-19 00:48:24.383 20349-20407/? D/ClClient: Not sending keepalive.  Current connection state=STOPPED

我还会引入MainActivity.java和activity_main.xml:

MainActivity.java

import android.*;
import android.Manifest;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d("MainActivity","onCreate");
    } 
}

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.artfara.apps.kipper.MainActivity">

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_marginStart="108dp"
        android:layout_marginTop="117dp"
        android:id="@+id/textView" />
</RelativeLayout>

提前感谢您的任何帮助!

2 个答案:

答案 0 :(得分:0)

也许您需要明确设置默认活动。

<category android:name="android.intent.category.DEFAULT"/>

尝试将其放入MapsActivity意图过滤器中。

<activity android:name=".MapsActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

答案 1 :(得分:0)

当找不到给定的包,应用程序或组件名称时抛出此异常,请检查:

1)您的包裹名称是否正确。

2)您提到的LAUNCHER ACTIVITY活动确实存在于已定义的包

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="check_here">