English 中文(简体)
特定活动的发射器
原标题:Launch Android App with Specific Activity

当发射或恢复发射时,我谨根据共用防御装置中的变量,将用户转而从事具体活动。

To do this I was considering having a method that checks for SharedPreferences status variable and redirects to the correct activity:

private void launchRedirect(Context ctxt) {

    Integer status = AppPreferences.getStatus(this);
    Intent i =  new Intent(MainActivity.this, Activity1.class);

    switch (status) {
    case 0:
        i =  new Intent(MainActivity.this, Activity2.class);
    case 1:
        i =  new Intent(MainActivity.this, Activity3.class);
    case 2:
        i =  new Intent(MainActivity.this, Activity4.class);
    case 3:
        i =  new Intent(MainActivity.this, Activity5.class);    
    }
    startActivity(i);
}

然后,我可以把这种方法用在我估计的每项活动的每一平流方法中:

    public void onResume(Bundle savedInstanceState) {
    launchRedirect(this);
}

这意味着,用户在技术上不能回到最后一项活动,因为当他们打电话时,他们要求重新使用,并将转而与目前用户相对应。

我假定,这可能会导致一些循环的 b,尽管——这是否有更好的办法?

问题回答

我认为,这样做是正常的,但如果你在这种情况下需要结束主要行为的话,你也可以增加要求完成(......)的方法。

此外,不要忘记打破声明:

private void launchRedirect(Context ctxt) {

  Integer status = AppPreferences.getStatus(this);
  Intent i =  new Intent(MainActivity.this, Activity1.class);

  switch (status) {
  case 0:
    i =  new Intent(MainActivity.this, Activity2.class);
    break;
  case 1:
    i =  new Intent(MainActivity.this, Activity3.class);
    break;
  case 2:
    i =  new Intent(MainActivity.this, Activity4.class);
    break;
  case 3:
    i =  new Intent(MainActivity.this, Activity5.class);  
    break;  
  }
  startActivity(i);
  if (/* check if MainActivity should be closed */) {
    finish();
  }
}

请确保你根据你的导航活动更新优惠价值。 这将节省你对活动启动的不必要的检查。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签