Android Intent Always Crashes

I am trying to switch activities in android using intent. However no matter what I do, this always crashes. I read countless topics on the same question, none of which have helped. So I Am Forced to ask my own question.

When I Run This, the app simply crashes after the 4 seconds are up

Here Is My First Activity (Splash):

package com.redflamedeveloper.torch;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Splash extends Activity {
    /** Called when the activity is first created. */

    MediaPlayer mpSplash;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        mpSplash = MediaPlayer.create(this, R.raw.fire);                    //Splash Screen sound
        mpSplash.start();

        Thread logoTimer = new Thread(){                                    //4 Second Timer
            public void run() {
                try {
                    //Waits for 4 seconds
                    int logoTimer = 0;
                    while(logoTimer <4000){
                        sleep(100);
                        logoTimer = logoTimer + 100;
                    }
                    Intent intentMain = new Intent(Splash.this, Main.class);
                    startActivity(intentMain);
                }
                catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                finally {
                    finish();
                }
            }

        };

        logoTimer.start();                                          //Starts the thread logoTimer
    }


    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        mpSplash.release();                                         //ends sound
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        mpSplash.pause();                                           //pauses sound
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        mpSplash.start();                                           //Resumes sound
    }
}

My Second Activity (Main):

package com.redflamedeveloper.torch;

import android.app.Activity;
import android.hardware.Camera.Parameters;
import android.hardware.Camera;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.os.Handler;

/**
 * Created by Sasha on 8/12/13.
 */
public class Main extends Activity implements OnClickListener{

    private Camera mCamera;

    boolean torch = false;
    boolean flash = false;

    private Handler mHander = new Handler();

    private final Runnable mRunnable = new Runnable() {

        public void run() {
            while(flash) {
                if (torch==false) {
                    if( mCamera != null ){
                        Parameters params = mCamera.getParameters();
                        params.setFlashMode( Parameters.FLASH_MODE_TORCH );
                        mCamera.setParameters( params );
                        torch=true;
                    }
                } else {
                    if( mCamera != null ){
                        Parameters params = mCamera.getParameters();
                        params.setFlashMode( Parameters.FLASH_MODE_OFF );
                        mCamera.setParameters( params );
                        torch=false;
                    }
                }
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.main);

        Button bTorch = (Button) findViewById(R.id.bTorch);
        Button bFlash  = (Button) findViewById(R.id.bFlash);
        Button bHelp = (Button) findViewById(R.id.bHelp);
        Button bMorse = (Button) findViewById(R.id.bMorse);

        bTorch.setOnClickListener(this);
        bFlash.setOnClickListener(this);
        bHelp.setOnClickListener(this);
        bMorse.setOnClickListener(this);
    }

    private void startStrobe() {
        mHander.post(mRunnable);
    }

    public void onClick(View v) {
        switch(v.getId()){
            case R.id.bTorch:
                if (torch==false) {
                    if( mCamera != null ){
                        Parameters params = mCamera.getParameters();
                        params.setFlashMode( Parameters.FLASH_MODE_TORCH );
                        mCamera.setParameters( params );
                        torch=true;
                    }
                } else {
                    if( mCamera != null ){
                        Parameters params = mCamera.getParameters();
                        params.setFlashMode( Parameters.FLASH_MODE_OFF );
                        mCamera.setParameters( params );
                        torch=false;
                    }
                }
            break;
            case R.id.bFlash:
                flash=!flash;
                startStrobe();
            break;
            case R.id.bHelp:
                Parameters params = mCamera.getParameters();
                params.setFlashMode( Parameters.FLASH_MODE_TORCH );
                mCamera.setParameters( params );

                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                params.setFlashMode( Parameters.FLASH_MODE_OFF );
                mCamera.setParameters( params );

                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                params.setFlashMode( Parameters.FLASH_MODE_TORCH );
                mCamera.setParameters( params );

                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                params.setFlashMode( Parameters.FLASH_MODE_OFF );
                mCamera.setParameters( params );

                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                params.setFlashMode( Parameters.FLASH_MODE_TORCH );
                mCamera.setParameters( params );

                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                params.setFlashMode( Parameters.FLASH_MODE_OFF );
                mCamera.setParameters( params );

                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                params.setFlashMode( Parameters.FLASH_MODE_TORCH );
                mCamera.setParameters( params );

                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                params.setFlashMode( Parameters.FLASH_MODE_OFF );
                mCamera.setParameters( params );

                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                params.setFlashMode( Parameters.FLASH_MODE_OFF );
                mCamera.setParameters( params );

                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            break;
            case R.id.bMorse:
                Intent intentMorse = new Intent(Main.this, Morse.class);
                Main.this.startActivity(intentMorse);
            break;
        }
    }
}

And My Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.redflamedeveloper.torch"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.redflamedeveloper.torch.Splash"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity
            android:name=".Main"
            android:label="@string/app_name" >
        </activity>

        <activity
            android:name=".Morse"
            android:label="@string/app_name" >
        </activity>

    </application>

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />

</manifest>

And Finally LogCat:

12-09 23:28:35.682    2110-2110/com.redflamedeveloper.torch W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40c47a68)
12-09 23:28:35.692      637-674/? E/android.os.Debug﹕ !@Dumpstate > dumpstate -k -t -n -z -d -o /data/log/dumpstate_app_error
12-09 23:28:35.692    2110-2110/com.redflamedeveloper.torch E/AndroidRuntime﹕ FATAL EXCEPTION: main
    android.app.SuperNotCalledException: Activity {com.redflamedeveloper.torch/com.redflamedeveloper.torch.Main} did not call through to super.onCreate()
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1936)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
            at android.app.ActivityThread.access$600(ActivityThread.java:128)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4517)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
            at dalvik.system.NativeStart.main(Native Method)
12-09 23:28:35.692      637-647/? W/ActivityManager﹕ Force finishing activity com.redflamedeveloper.torch/.Main
12-09 23:28:35.702    2144-2144/? I/dumpstate﹕ Check if stand-alone
12-09 23:28:35.712    2144-2144/? I/dumpstate﹕ begin
12-09 23:28:36.523    1268-1281/? E/MP-Decision﹕ DOWN Ld:54 Ns:1.100000 Ts:190 rq:0.000000 seq:196.000000
12-09 23:28:37.023    637-25450/? W/SignalStrength﹕ getGsmLevel=4
12-09 23:28:37.023    637-25450/? W/SignalStrength﹕ getLevel=4 (SignalStrength: 14 0 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 2147483647 gsm|lte 0x4)
12-09 23:28:37.023      771-771/? W/SignalStrength﹕ getGsmLevel=4
12-09 23:28:37.023      771-771/? W/SignalStrength﹕ getLevel=4 (SignalStrength: 14 0 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 2147483647 gsm|lte 0x4)
12-09 23:28:37.023      771-771/? W/SignalStrength﹕ getGsmLevel=4
12-09 23:28:37.023      771-771/? W/SignalStrength﹕ getLevel=4 (SignalStrength: 14 0 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 2147483647 gsm|lte 0x4)
12-09 23:28:37.023      771-771/? D/STATUSBAR-NetworkController﹕ onSignalStrengthsChanged signalStrength=SignalStrength: 14 0 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 2147483647 gsm|lte 0x4 level=4
12-09 23:28:37.023      637-884/? W/AlarmManager﹕ FACTORY_ON= 0
12-09 23:28:37.774    1268-1281/? E/MP-Decision﹕ UP Ld:61 Nw:1.990000 Tw:140 rq:2.300000 seq:147.000000
12-09 23:28:38.164      329-329/? E/SMD﹕ DCD ON
12-09 23:28:38.665      336-582/? D/AudioStreamOutALSA﹕ standby
12-09 23:28:38.665      336-582/? D/ALSAModule﹕ s_standby: handle 0x10454c0 h 0x0
12-09 23:28:38.665      336-582/? E/ALSAModule﹕ s_standby handle h 0x10e2180
12-09 23:28:38.865      336-582/? D/alsa_ucm﹕ snd_use_case_set(): uc_mgr 0xfe8968 identifier _verb value Inactive
12-09 23:28:38.865      336-582/? D/alsa_ucm﹕ set_use_case_ident_for_all_devices(): HiFi
12-09 23:28:38.865      336-582/? D/alsa_ucm﹕ Set mixer controls for HiFi enable 0
12-09 23:28:38.865      336-582/? D/alsa_ucm﹕ Set mixer controls for HiFiSpeaker enable 0
12-09 23:28:38.865      336-582/? D/alsa_ucm﹕ snd_use_case_set(): uc_mgr 0xfe8968 identifier _disdev value Main Mic
12-09 23:28:38.865      336-582/? D/alsa_ucm﹕ disdev: device Main Mic not enabled or not active, no need to disable
12-09 23:28:38.865      336-582/? D/alsa_ucm﹕ snd_use_case_set(): uc_mgr 0xfe8968 identifier _disdev value Speaker
12-09 23:28:38.865      336-582/? E/alsa_ucm﹕ Empty list
12-09 23:28:38.865      336-582/? D/alsa_ucm﹕ set current output is none
12-09 23:28:38.865      336-582/? D/alsa_ucm﹕ Set mixer controls for Speaker enable 0
12-09 23:28:39.075    1268-1281/? E/MP-Decision﹕ DOWN Ld:18 Ns:1.100000 Ts:190 rq:0.000000 seq:196.000000
12-09 23:28:40.557      319-542/? D/VoldCmdListener﹕ asec list
12-09 23:28:40.557      319-542/? D/VoldCmdListener﹕ CommandListener::AsecCmd::runCommand -> --
12-09 23:28:40.707      637-698/? D/KeyguardViewMediator﹕ setHidden false
12-09 23:28:40.707      637-698/? D/KeyguardViewMediator﹕ setHidden false
12-09 23:28:40.707      637-698/? D/DEFERED_APP_VISIBILITY﹕ tweaking closing app
12-09 23:28:40.707      637-698/? D/DEFERED_APP_VISIBILITY﹕ tweaking closing app
12-09 23:28:40.717      637-698/? D/KeyguardViewMediator﹕ setHidden false
12-09 23:28:40.737      637-698/? D/KeyguardViewMediator﹕ setHidden false
12-09 23:28:40.747      637-698/? D/KeyguardViewMediator﹕ setHidden false

I am At my wits end. All help will be greatly appreciated

Sasha

Answers


You need to call super.onCreate(savedInstanceState); in the onCreate method of Main.class


Your second activity does not call super.onCreate(savedInstanceState). It says so in the logcat


Need Your Help

Any idea how to let S3 serve “maintenance mode” page?

dns amazon-s3 amazon-ec2 amazon maintenance

Say, you have a Rails (or actually any other kind) application running on Amazon EC2, and whenever you perform some maintenance, which might include shutting down or re-creating your instances, you...

WCF, return list of Known Types

wcf web-services known-types

I have a server side service called ConstructionManager, one of its operation is GetAll() which return a list of constructions. Construction is a data contract, and there are several types which in...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.