Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 用户选择首先启动哪个活动?_Android_Android Activity - Fatal编程技术网

Android 用户选择首先启动哪个活动?

Android 用户选择首先启动哪个活动?,android,android-activity,Android,Android Activity,我需要帮助,请用户选择首先启动哪个活动 我有3个活动和设置活动,我希望用户选择一个活动首先启动并保存 如果有人能为我提供正确的代码或示例,我将不胜感激 <activity android:label="@string/app_name" android:screenOrientation="portrait" android:name="com.example.Test" android:theme="@style/Theme.FullScreen">

我需要帮助,请用户选择首先启动哪个活动

我有3个活动和设置活动,我希望用户选择一个活动首先启动并保存

如果有人能为我提供正确的代码或示例,我将不胜感激

<activity
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:name="com.example.Test" 
    android:theme="@style/Theme.FullScreen">
    <intent-filter >
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

当我启动应用程序时,总是以Test.class启动 我如何设置用户选择哪一个开始


提前感谢。

创建一个
活动
作为应用程序的主要入口点。此活动将检查用户是否选择了默认活动。如果他有,那么该活动将启动该活动并自行关闭。否则,它将提示用户选择默认活动

示例代码(您需要进行一些修改以满足您的需求):

公共类MainActivity扩展活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
最终SharedPreferences sharedPref=getPreferences(模式\私人);
int choice=sharedPref.getInt(“默认活动”,-1);
如果(选项==-1){
//向用户显示选择默认活动的选项
//例如,使用列表对话框,然后将相应的选项保存到
//共同偏好
字符串[]activities={“Activity 1”、“Activity 2”、“Activity 3”};
AlertDialog.Builder=新生成器(此);
builder.setAdapter(
新阵列适配器(此,
android.R.layout.simple_list_item_1,活动),
新的OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
SharedPreferences.Editor=sharedPref.edit();
putInt(“默认_活动”,其中);
commit();
启动活动(哪些活动);
}
}).show();
}否则{
//启动活动并关闭此活动
发射活动(选择);
}
}
私有void启动活动(int选项){
开关(选择){
案例0:
startActivity(新意图(本,Activity1.class));
打破
案例1:
startActivity(新意图(本,Activity2.class));
打破
案例2:
startActivity(新意图(本,Activity3.class));
打破
}
完成();
}
}

创建一个
活动
作为应用程序的主要入口点。此活动将检查用户是否选择了默认活动。如果他有,那么该活动将启动该活动并自行关闭。否则,它将提示用户选择默认活动

示例代码(您需要进行一些修改以满足您的需求):

公共类MainActivity扩展活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
最终SharedPreferences sharedPref=getPreferences(模式\私人);
int choice=sharedPref.getInt(“默认活动”,-1);
如果(选项==-1){
//向用户显示选择默认活动的选项
//例如,使用列表对话框,然后将相应的选项保存到
//共同偏好
字符串[]activities={“Activity 1”、“Activity 2”、“Activity 3”};
AlertDialog.Builder=新生成器(此);
builder.setAdapter(
新阵列适配器(此,
android.R.layout.simple_list_item_1,活动),
新的OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
SharedPreferences.Editor=sharedPref.edit();
putInt(“默认_活动”,其中);
commit();
启动活动(哪些活动);
}
}).show();
}否则{
//启动活动并关闭此活动
发射活动(选择);
}
}
私有void启动活动(int选项){
开关(选择){
案例0:
startActivity(新意图(本,Activity1.class));
打破
案例1:
startActivity(新意图(本,Activity2.class));
打破
案例2:
startActivity(新意图(本,Activity3.class));
打破
}
完成();
}
}

创建临时活动。在此活动中,用户可以选择活动名称。保存选定的活动名称(使用此参数“活动”)(例如:FirstActivity、SecondActivity、ThirdActivity)

GetSharedPreferenceStringValue=>编写此函数

算法 并在temp活动中控制它(在onCreate函数中)

1-如果存在名称为“活动”的值,则再次控制它

 1.1-If getSharedPreferencesStringValue("activity").equals("FirstActivity")

  -Redirect FirstActivity
 1.2-If getSharedPreferencesStringValue("activity").equals("SecondActivity")

  -Redirect SecondActivity
 1.2-If getSharedPreferencesStringValue("activity").equals("ThirdActivity")

  -Redirect ThirdActivity
2-如果没有名称为“活动”的值


致以最诚挚的问候,

创建临时活动。在此活动中,用户可以选择活动名称。保存选定的活动名称(使用此参数“活动”)(例如:FirstActivity、SecondActivity、ThirdActivity)

GetSharedPreferenceStringValue=>编写此函数

算法 并在temp活动中控制它(在onCreate函数中)

1-如果存在名称为“活动”的值,则再次控制它

 1.1-If getSharedPreferencesStringValue("activity").equals("FirstActivity")

  -Redirect FirstActivity
 1.2-If getSharedPreferencesStringValue("activity").equals("SecondActivity")

  -Redirect SecondActivity
 1.2-If getSharedPreferencesStringValue("activity").equals("ThirdActivity")

  -Redirect ThirdActivity
2-如果没有名称为“活动”的值


致以最诚挚的问候,

您可以将一个空活动作为默认启动活动,该活动只需查看设置(我假设为SharedReferences),然后从3中调用相应的活动并自行关闭。感谢您的重播,我同意您的看法SharedReferences是最好的,但是我不知道如何实现这一点。你可以使用SharedReferences来实现它。当用户选择
 2.1-Open temp activity

 2.2-Show activity list

 2.3-After than user chose an activity, save it preferences

 2.4-And open that activity