Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

android - Package rename and error "Activity class does not exist"

I have a splash activity which starts another activity like this

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();
    }

To start another activity I use string parameter for the Intent constructor. The corresponding class is paired with the splash string like this

   <?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>

This works flawlessly UNTIL I rename the package name. I rename the package name in the Manifest by using refactoring and the IDE renames all other classes accordingly. But when I want to start newly renamed project, I face an error

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.

It seems that the app tries to start the Splash activity using OLDpath/NEWpath.Splash path and the error is there, but I can't find why it is using such path.

I use IntelliJ IDE. Any ideas? Could it be in the Filter in the 2nd activity in the Manifest?!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is a bug in Android Studio. To fix it:

  1. Close Studio.
  2. Remove .idea/workspace.xml
  3. Launch Studio.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...