开发者

How can I change Activity with an Intent that is located in different folder?

The structure of my project is as

-src
    -folder1
         Activity1.java
         otherfiles.java
     -folder2
         `Activity2.java

Now my question: How can I call Activity2 fr开发者_开发百科om Activity1?

       Intent myintent = new Intent(getContext(), ** Activity2.class** ) // <<--

Did not work :)


Intent myintent = new Intent(getContext(), your.folder.path.Activity2 )


Actually you can fix that by changing the declaration of your activity in AndroidManifest file. You need to do something like this :

<activity android:name="com.android.examples.activities.Activity2" android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" android:screenOrientation="portrait"/>
            </intent-filter>
</activity>

com.android.examples.activities.Activity2 - is the name of package where your class is

And after that you just call your activity like :

Intent intent = new Intent(Activity1.this, Activity2.class);


Solution: In activity1, import activity2.

For example, I faced the same issue where my loginactivity and accountpasswordActivity where in different directories.

import com.chiguruecospace.chiguru_mobile_app.loginactivity;

I added this code in my accountpasswordActivity and it worked.

File Hierarchy

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜