Pradeep Pradeep - 6 months ago 20
Android Question

my apk stopped when starting to another activity

Im new to android development. Im trying to open second activity by clicking button, but when I try my apk stopped. can someone help me figure out my error. Below are my code

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pradeep.findme">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainPlayActivity"
android:screenOrientation="landscape"
android:parentActivityName=".MainActivity">

</activity>
</application>
</manifest>


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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.pradeep.findme.MainActivity"
android:background="@drawable/uibg"
android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" >
<Button
android:layout_width="90dp"
android:layout_height="50dp"
android:id="@+id/pbutton"
android:background="@drawable/play"
android:textColor="#0760db"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
/>
<Button
android:layout_width="90dp"
android:layout_height="50dp"
android:id="@+id/ibutton"
android:layout_gravity="bottom"
android:background="@drawable/inst"
android:textColor="#0760db"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/pbutton"
android:layout_marginLeft="10dp"/>
<Button
android:layout_width="90dp"
android:layout_height="50dp"
android:id="@+id/sbutton"
android:layout_gravity="bottom"
android:background="@drawable/story"
android:textColor="#0760db"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/ibutton"
android:layout_marginLeft="10dp"/>
<Button
android:layout_width="90dp"
android:layout_height="50dp"
android:id="@+id/ebutton"
android:layout_gravity="bottom"
android:background="@drawable/exit"
android:textColor="#0760db"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/sbutton"
android:layout_marginLeft="10dp" />
</RelativeLayout>




MainActivity.java

public class MainActivity extends Activity {
Button Quit,Play,Story,Ins;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.activity_main);

Quit = (Button)findViewById(R.id.ebutton);
Play= (Button)findViewById(R.id.pbutton);
Story= (Button)findViewById(R.id.sbutton);
Ins= (Button)findViewById(R.id.ibutton);

Quit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
finish();
}
});

Play.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent = new Intent(getApplicationContext(), MainPlayActivity.class);
startActivity(intent);
}
});

}
}


activity_main_play.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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.pradeep.findme.MainPlayActivity"
android:background="@drawable/room2"
android:id="@+id/playscreen"
android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen">
</RelativeLayout>


MainPlayActivity.java

public class MainPlayActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_play);
}
}

Answer

You forgot to apply theme. Put android:theme="@style/AppTheme" in your manifest file like:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
Comments