1

I'm new so excuse me if being not good with my question at first place :D here is my code which works great :

package com.github.chenxiaolong.dualbootpatcher;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;


public class Patch extends Activity{

MediaPlayer mpbuttonclick;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    setContentView(R.layout.patcher);

    mpbuttonclick = MediaPlayer.create(this, R.raw.keypress);

    Button sumbitButton = (Button) findViewById(R.id.submitbutton);
    sumbitButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v){
        EditText passwordEditText = (EditText) findViewById(R.id.passwordedittext);
                    if(passwordEditText.getText().toString().equals("1234")){
                        startActivity(new Intent(".MainActivity"));
                        mpbuttonclick.start();


                    }}});
    }}

and here is my AndroidManifest :

<activity
            android:name=".MainActivity"
            android:label="@string/app_name_release"
            android:theme="@style/DrawerActivityTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Patch"
            android:label="@string/app_name_release"
            android:theme="@style/DrawerActivityTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

it compiles well but when i input 1234 to text it force closes the app here is logcats logs can you correct my code and explain me ? i want to learn too :P thanks in advance

Mr.Nikan
  • 67
  • 9
  • Possible duplicate of [How to start new activity on button click](http://stackoverflow.com/questions/4186021/how-to-start-new-activity-on-button-click) You can also check -- [android developers site](http://developer.android.com/training/basics/firstapp/starting-activity.html) – AL. Mar 09 '16 at 00:30
  • shadab ansari solution worked perfectly for me – Mr.Nikan Mar 09 '16 at 00:31
  • His answer is correct, but you could've done this alone if you googled a way first. StackOverflow and Android Developers Site mostly has the answers to the basic questions. Just try to look around first. :) – AL. Mar 09 '16 at 00:36
  • @sept I'm sorry sir as i mention above I'm new to Android development so i did this code and added to my app and fixed all bugs but didnt know how to fix this one so i came and write here .... i didnt know what to google ... also android website is blocked here duo the limits... – Mr.Nikan Mar 09 '16 at 00:41
  • No worries. Just wanted to let you know of your options for future use. ;) – AL. Mar 09 '16 at 01:12

3 Answers3

0

You can launch any activity using several ways . For your case, you can do that by writing :

startActivity(new Intent(Patch.this, MainActivity.class));
Shadab Ansari
  • 7,022
  • 2
  • 27
  • 45
0

You have not declare the Patch.this in side intent use it like

startActivity(new Intent(Patch.this,MainActivity.class));

hope it will work..

Ritesh
  • 876
  • 9
  • 14
0

Try deleting the "intent-filter" section of the second Activity in AndroidManifest.xml

Your AndroidManifest.xml should look like:

<activity
  android:name=".MainActivity"
  android:label="@string/app_name_release"
  android:theme="@style/DrawerActivityTheme">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

<activity
  android:name=".Patch"
  android:label="@string/app_name_release"
  android:theme="@style/DrawerActivityTheme">
</activity>
chihau
  • 363
  • 4
  • 7