我有一个启动另一个类似这样的 Activity 的启动 Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
final Thread splashThread = new Thread() {
@Override
public void run() {
try {
int wait = 0;
while (_isActive && (_splashTime > wait)) {
sleep(100);
if (_isActive) {
wait += 100;
}
}
} catch (InterruptedException e) {
Log.d(TAG, e.getMessage());
} finally {
startActivity(new Intent("com.path1.path2.SomeActivity"));
finish();
}
}
};
splashThread.start();
}
要开始另一个 Activity ,我使用 Intent
构造函数的字符串参数。相应的类与这样的启动字符串配对
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.path1.path2"
android:versionCode="2"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4"/>
<!--permissions-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name=".SplashActivity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".SomeActivity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="com.path1.path2.SomeActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".OtherActivity" android:label="@string/app_name"
/>
<!--services-->
<service android:name=".AlarmService"/>
</application>
</manifest>
在我重命名包名称之前,这可以完美运行。我通过使用重构重命名 list 中的包名称,IDE 相应地重命名所有其他类。但是当我想开始新重命名的项目时,我遇到了一个错误
Launching application: com.path1.pathOLD/com.path1.path2.SplashActivity.
DEVICE SHELL COMMAND: am start -n "com.path1.pathOLD/com.path1.path2.SplashActivity"
Starting: Intent { cmp=com.path1.pathOLD/com.path1.path2.SplashActivity }
Error type 3
Error: Activity class {com.path1.pathOLD/com.path1.path2.SplashActivity} does not exist.
似乎该应用程序尝试使用 OLDpath/NEWpath.Splash
路径启动 Splash Activity 并且错误在那里,但我找不到它为什么使用这样的路径。
我使用 IntelliJ IDE。有任何想法吗?会不会在 Manifest 的第二个 Activity 的过滤器中?!
最佳答案
这是 Android Studio 中的一个错误。修复它:
- 关闭工作室。
- 删除 .idea/workspace.xml
- 启动工作室。
关于android - 包重命名和错误 "Activity class does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8180185/