ボタンをクリックすると、白い画面のみが表示され、次のアクティビティは表示されません。私はそれが起こる理由を見つけることができませんplsは私に解決策を与えます......私のコード全体はここにあります
ActivityMain.java
package com.rahul.intentswitchingwithdata;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void go(View v){
Intent i= new Intent(this,Next.class);
startActivity(i);}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.rahul.intentswitchingwithdata.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="go"/>
</RelativeLayout>
Next.java
public class Next extends Activity {
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle
persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.next);
}
}
next.xml
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#123"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
マニフェスト.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rahul.intentswitchingwithdata">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Next"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
間違ったonCreate
メソッドを「オーバーライド」しました。
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle
persistentState)
代わりにこれを使用する必要があります。
@Override
public void onCreate(Bundle savedInstanceState){...code}
onCreate(Bundle)
初期化に使用されるとは、ビューなどのすべてのUI初期化が行われる場所を意味し、詳細についてはドキュメントリンクを参照してください
onCreate(Bundle, PersistableBundle)
それ自体が示唆しているように、それは再作成中に古いインテント(このアクティビティに最初に提供された)を再利用する永続的な平均に使用さpersistableMode
れます。アクティビティにフラグを追加して再利用を有効にし、再起動後もアクティビティが永続化されるようにすることができます。他のオプションの詳細については、このドキュメントリンクを試してください。
注:onCreate(Bundle, PersistableBundle)
APIレベル21(Android Lollipop 5.0)以降でのみ使用できます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加