android - Cannot redirect to next page -
here home.java
code. not redirecting next page, if change intent (home.this, mainactivity.class):
import android.app.activity; import android.content.intent; import android.os.bundle; public class home extends activity { protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.fragment_main); thread timer = new thread() { public void run() { try{ sleep(2000); } catch (interruptedexception e) { e.printstacktrace(); } { intent openmainactivity = new intent("com.droid.mine.mainactivity"); startactivity(openmainactivity); } } }; timer.start();}{ } }
here mainactivity.java
code. i.e next page getting error classcastexception:
import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; public class mainactivity extends activity { button log,sign; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.register); log = (button) findviewbyid(r.id.register); sign = (button) findviewbyid(r.id.linktologin); log.setonclicklistener((onclicklistener) this); sign.setonclicklistener((onclicklistener) this); } public void onclick(view v) { switch(v.getid()) { case r.id.register: break; case r.id.linktologin: intent = new intent(); i.setclass(mainactivity.this,register.class); startactivity(i); break; } } }
manifest follows:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.droid.mine" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" 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.droid.mine.home" 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=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name=".mainactivity" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
here logcat error:
04-21 15:59:07.156: i/applicationpackagemanager(21341): csccountry not german : ins 04-21 15:59:07.273: d/dalvikvm(21341): gc_external_alloc freed 78k, 47% free 2860k/5379k, external 408k/517k, paused 95ms 04-21 15:59:09.648: w/dalvikvm(21341): threadid=9: thread exiting uncaught exception (group=0x40018578) 04-21 15:59:09.710: e/androidruntime(21341): fatal exception: thread-10 04-21 15:59:09.710: e/androidruntime(21341): android.content.activitynotfoundexception: no activity found handle intent { act=com.droid.mine.mainactivity } 04-21 15:59:09.710: e/androidruntime(21341): @ android.app.instrumentation.checkstartactivityresult(instrumentation.java:1409) 04-21 15:59:09.710: e/androidruntime(21341): @ android.app.instrumentation.execstartactivity(instrumentation.java:1379) 04-21 15:59:09.710: e/androidruntime(21341): @ android.app.activity.startactivityforresult(activity.java:2827) 04-21 15:59:09.710: e/androidruntime(21341): @ android.app.activity.startactivity(activity.java:2933) 04-21 15:59:09.710: e/androidruntime(21341): @ com.droid.mine.home$1.run(home.java:21)
here register.java class
package com.droid.mine; import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.view; import android.widget.button; public class register extends activity implements view.onclicklistener { button backlog,regg; protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.login); backlog = (button) findviewbyid(r.id.loginn); regg = (button) findviewbyid(r.id.signup); backlog.setonclicklistener(this); } public void onclick (view v) { switch(v.getid()) { case r.id.loginn: break; case r.id.signup: intent in = new intent(); in.setclass(register.this,mainactivity.class); startactivity(in); break; }
} }
firstly
change intent this:
intent intent = new intent(home.this,mainactivity.class); startactivity(intent);
secondly
just update manifest this:
<uses-sdk android:minsdkversion="8" 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.droid.mine.home" 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="com.droid.mine.mainactivity" android:label="@string/app_name" > </activity> <activity android:name="com.droid.mine.register" android:label="@string/app_name" > </activity> </application>
use home activity
package com.example.pms; import android.app.activity; import android.content.context; import android.content.intent; import android.os.bundle; import android.os.handler; import android.view.motionevent; import android.widget.toast; public class splashscreen extends activity { /* * thread process splash screen events */ private thread msplashthread; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // splash screen view setcontentview(r.layout.activity_splash); final splashscreen msplashscreen=this; /* * thread wait splash screen events */ msplashthread =new thread(){ @override public void run(){ try { synchronized(this){ // wait given period of time or exit on touch wait(3000); } } catch(interruptedexception ex){ } finish(); // run next activity startactivity(new intent(getbasecontext(), mainactivity.class)); new runnable() { @override public void run() { msplashthread.stop(); } }; } }; msplashthread.start(); } /** * processes splash screen touch events */ @override public boolean ontouchevent(motionevent event) { if(event.getaction() == motionevent.action_down) { synchronized(msplashthread){ msplashthread.notifyall(); } } return true; } }
Comments
Post a Comment