java - Android app unable to launch an activity after splash activity -
my app unable move 2nd activity that's startingpoint after launching splash activity. app closes saying "unfortunately thenewboston has stopped working."
i attaching relevant files. hope can me this. startingpoint.java
package com.example.thenewboston; import android.app.activity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.textview; public class startingpoint extends activity { int counter; button add,sub; textview display; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_starting_point); counter=0; add=(button)findviewbyid(r.id.addbutton); sub=(button)findviewbyid(r.id.subbutton); display=(textview) findviewbyid(r.id.display); add.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub counter++; display.settext("your total = " + counter); } }); sub.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub counter--; display.settext("your total = " + counter); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.starting_point, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
splash.java
package com.example.thenewboston; import android.app.activity; import android.content.intent; import android.os.bundle; public class splash extends activity{ @override public void oncreate(bundle tv) { // todo auto-generated method stub super.oncreate(tv); setcontentview(r.layout.splash); thread timer = new thread(){ public void run(){ try{ sleep(5000); }catch(interruptedexception e){ e.printstacktrace(); }finally{ intent openstatingpoint= new intent("com.thenewboston.startingpoint"); startactivity(openstatingpoint); } } }; timer.start(); } }
manifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.thenewboston" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="23" android:targetsdkversion="23" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".startingpoint" android:label="@string/app_name" > <intent-filter> <action android:name="com.example.thenewboston.startingpoint" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity> <activity android:name=".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> </application> </manifest>
try change code below:
intent openstatingpoint= new intent(splash.this,startingpoint.class); startactivity(openstatingpoint);
explanation:
the constructor used here takes two parameters: context first parameter (splash.this used because activity class subclass of context) class of app component system should deliver intent (in case, activity should started, here startingpoint.class)
see more build intent
Comments
Post a Comment