Java 在MainActivity和FirstChildActivity之间插入NewChildDaActivity,并将默认ChildActivity更改为NewChildActivity
各位朋友: 谢谢大家一如既往的支持 我开发了一个具有登录功能的考试应用程序 以前,该应用程序有3个活动(MainActivity、WelcomeScreenActivity和QuestionsActivity)。这个应用程序运行得很好 但是,当用户从MainActivity登录时,将显示WelcomeScreenActivity。 但是我需要在main活动和WelcomeScreenActivity之间插入另一个活动(PROFILE_活动),这样,当用户成功登录时,应用程序将显示用户的PROFILEACTIVITY 页面下方的图片 新档案活动之前的上一个代码 MainActivity.java代码Java 在MainActivity和FirstChildActivity之间插入NewChildDaActivity,并将默认ChildActivity更改为NewChildActivity,java,android,android-intent,android-activity,manifest,Java,Android,Android Intent,Android Activity,Manifest,各位朋友: 谢谢大家一如既往的支持 我开发了一个具有登录功能的考试应用程序 以前,该应用程序有3个活动(MainActivity、WelcomeScreenActivity和QuestionsActivity)。这个应用程序运行得很好 但是,当用户从MainActivity登录时,将显示WelcomeScreenActivity。 但是我需要在main活动和WelcomeScreenActivity之间插入另一个活动(PROFILE_活动),这样,当用户成功登录时,应用程序将显示用户的PROFI
@Override
protected void onPostExecute(Void result){
if (!responseData.equals( "User Not Found" )) {
message = "Welcome";
data = responseData;//store the user id from the server in data
//Bundle bundle = new Bundle();//bundle the message and parse it to the next activity
//bundle.putString("dispMsg", message);//bundle the message using the variable dispMsg
//intent.putExtras(bundle);
startActivity(intent);
statusBar.setText(message);
} else {
message = responseData;//"Incorrect Username or Password. Try again!";
statusBar.setText(message);
}
super.onPostExecute(result);
}
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examinationportal">
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DisplayWelcomeScreen"
android:label="@string/welcome_screen_title"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".CSS_342_Questions"
android:allowTaskReparenting="true"
android:label="@string/question_screen"
android:parentActivityName=".DisplayWelcomeScreen">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".DisplayWelcomeScreen" />
</activity>
<activity
android:name=".RegisterUserActivity"
android:label="@string/new_user_form"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examinationportal">
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ProfileAcvitity"
android:label="@string/student_profile"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".RegisterUserActivity"
android:label="@string/new_user_form"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
public class ProfileAcvitity extends AppCompatActivity {
public Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_acvitity);
intent = getIntent();
}
DisplayWelcomeScreenActivity.java代码
此活动在成功登录后显示
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_welcome_screen);
// Get the Intent that started this activity and extract the string
intent = getIntent();
}
要将此WelcomeActivity传递到下一个QuestionsActivity,下面的代码将在buttonclick()事件上执行此操作
使用下面的代码显示QuestionsActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_css_342__questions);
// Get the Intent that started this activity and extract the string
intent = getIntent();
bundle = getIntent().getExtras();
showCode = bundle.getString("dispCode");
qNum = bundle.getInt("qNum");
}
下面的代码是清单xml,它将3个活动链接在一起以实现正确的导航
AndroidManifest.XML代码
@Override
protected void onPostExecute(Void result){
if (!responseData.equals( "User Not Found" )) {
message = "Welcome";
data = responseData;//store the user id from the server in data
//Bundle bundle = new Bundle();//bundle the message and parse it to the next activity
//bundle.putString("dispMsg", message);//bundle the message using the variable dispMsg
//intent.putExtras(bundle);
startActivity(intent);
statusBar.setText(message);
} else {
message = responseData;//"Incorrect Username or Password. Try again!";
statusBar.setText(message);
}
super.onPostExecute(result);
}
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examinationportal">
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DisplayWelcomeScreen"
android:label="@string/welcome_screen_title"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".CSS_342_Questions"
android:allowTaskReparenting="true"
android:label="@string/question_screen"
android:parentActivityName=".DisplayWelcomeScreen">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".DisplayWelcomeScreen" />
</activity>
<activity
android:name=".RegisterUserActivity"
android:label="@string/new_user_form"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examinationportal">
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ProfileAcvitity"
android:label="@string/student_profile"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".RegisterUserActivity"
android:label="@string/new_user_form"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
public class ProfileAcvitity extends AppCompatActivity {
public Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_acvitity);
intent = getIntent();
}
新建ProfileActivity.java代码
@Override
protected void onPostExecute(Void result){
if (!responseData.equals( "User Not Found" )) {
message = "Welcome";
data = responseData;//store the user id from the server in data
//Bundle bundle = new Bundle();//bundle the message and parse it to the next activity
//bundle.putString("dispMsg", message);//bundle the message using the variable dispMsg
//intent.putExtras(bundle);
startActivity(intent);
statusBar.setText(message);
} else {
message = responseData;//"Incorrect Username or Password. Try again!";
statusBar.setText(message);
}
super.onPostExecute(result);
}
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examinationportal">
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DisplayWelcomeScreen"
android:label="@string/welcome_screen_title"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".CSS_342_Questions"
android:allowTaskReparenting="true"
android:label="@string/question_screen"
android:parentActivityName=".DisplayWelcomeScreen">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".DisplayWelcomeScreen" />
</activity>
<activity
android:name=".RegisterUserActivity"
android:label="@string/new_user_form"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examinationportal">
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ProfileAcvitity"
android:label="@string/student_profile"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".RegisterUserActivity"
android:label="@string/new_user_form"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
public class ProfileAcvitity extends AppCompatActivity {
public Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_acvitity);
intent = getIntent();
}
日志信息
请帮我解决这个问题
多谢各位
在您的
AndroidManifest.xml
文件中添加这些行将解决您的问题。显然是说DisplayWelcomeScreen
未在清单文件中定义。因此,请在清单中定义DisplayWelcomeScreen
Activity。酋长,在你获得logcat信息之前,你还没有完全阅读我的帖子。我说我正在DisplayWelcomeActivity之前插入一个新活动。这就是为什么我删除了DisplayWelcomeActivity并改为放置ProfileActivity,这会引发一个崩溃错误。亲爱的朋友,我说我正在DisplayWelcomeActivity之前插入一个新活动。这就是为什么我删除了DisplayWelcomeActivity并改为放置ProfileActivity,它现在抛出了一个崩溃错误。您在上面放置的代码将只移动到DisplayWelcomeActivity而不是ProfileActivity。这不是我想展示的活动。