简体   繁体   English

从另一个活动开始Main活动

[英]Starting the Main activity from another activity

I am trying to achieve following case on Android, but no success: 1) Launch Application (Launcher Activity which is a subclass of Base Activity). 我正在尝试在Android上实现以下情况,但没有成功:1)启动应用程序(Launcher Activity,它是Base Activity的子类)。 The Base Activity has code as follows: 基本活动的代码如下:

///This is in BaseActivity
@Override
public void onCreate(Bundle instance)
{
    super.onCreate(instance);
    //Config.isLoggedIn() is a static function.
    if(! Config.isLoggedIn())
    {
        ////Config.startLoginActivity is a static function
        Config.startLoginActivity(this, getIntent());
        finish();
    }
}

The Config.startLoginActivity functions is defined as Config.startLoginActivity函数定义为

public static void startLoginActivity(final Context ctx, final Intent finishIntent)
{
    Intent i = new Intent(ctx, ItemListActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.putExtra("FINISH_INTENT", finishIntent);
    ctx.startActivity(i);
}

Now, the ItemListActivity contains a list of Items as {Item1, Item2, Item3}. 现在,ItemListActivity包含项列表,如{Item1,Item2,Item3}。 In ItemListActivity, I am saving the passed "finishIntent" as 在ItemListActivity中,我将传递的“ finishIntent”保存为

///This is ItemListActivity onCreate Method
if(getIntent().hasExtra("FINISH_INTENT"))
        mFinishIntent = getIntent().getParcelableExtra("FINISH_INTENT");

and the onItemListSelected method is described as follows : 并且onItemListSelected方法描述如下:

@Override
public void onItemSelected(String id) {
Config.setLogInState(true);
    if(mFinishIntent != null)
    {

        Log.i("ITEMLISTACTIVITY", "Class Name = " + mFinishIntent.getClass().getName());
        Log.i("ITEMLISTACTIVITY", "Starting mFinishIntent Activity");
        startActivity(mFinishIntent);
        finish();
    }
}

But the issue is the Main Activity is not being launched again, Android takes me to the home screen instead. 但是问题是没有再次启动Main Activity,Android将我带到了主屏幕。 While looking for a solution, I saw that Google I/O app has the same implementation and that works flawlessly but in my case it is not. 在寻找解决方案时,我发现Google I / O应用具有相同的实现,并且可以完美地工作,但就我而言,却并非如此。 I am unable to figure it out. 我无法弄清楚。 Please help. 请帮忙。

Thanks in Advance. 提前致谢。

Manifest File is as follows : 清单文件如下:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.app.myapplication.ItemListActivity"
        android:label="@string/app_name" >
    </activity>

      <activity
        android:name="com.app.myapplication.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Ok Here is a quick help which works for 100 percent which I'm using not mostly but EVERYTIME! 好的,这里是一个快速帮助,它可以100%正常工作,我使用的不是大多数,而是每次! you must past it through intent and in your case here it is how it must look like. 您必须通过意图来克服它,并且在这种情况下,它必须是这样。

Intent intent = new intent(//name of your activity in which you are at the moment.this, //name of activity to which you want to go.class); Intent intent = new intent(//当前您所在的活动的名称。this,//您要进入的活动的名称.class); startActivity(intent); startActivity(intent);

Hope this will help 希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM