Im getting the error in the title when just messing around with android programming:
Code :
package co.uk.mypchealth.whatami;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread logoTimer = new Thread(){
public void run(){
try {
sleep(3000);
Intent menuIntent = new Intent("co.uk.mypchealth.whatami.JAVAMENU");
startActivity(menuIntent);
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
};
logoTimer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
and the manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.uk.mypchealth.whatami"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="co.uk.mypchealth.whatami.MainActivity"
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=".JavaMenu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="co.uk.mypchealth.whatami.JAVAMENU" />
<category android:name="android.intent.category.DEFUALT" />
</intent-filter>
</activity>
</application>
</manifest>
Im Hoping its something simple i mean jeeze the app does nothing yet lol.... i have the intent declared and and all the names i have checked and double checked ... just cant see the wood from the trees. Any help would be great.
Try,
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent menuIntent = new Intent(MainActivity.this, JavaMenu.class);
startActivity(menuIntent);
}
}, 3000);
try this :
<activity
android:name=".JavaMenu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="co.uk.mypchealth.whatami.JAVAMENU" />
<category android:name="android.intent.category.DEFUALT" />
</intent-filter>
</activity>
you have defined the app name in both activities try to change this activity declaration to :
<activity android:name="co.uk.mypchealth.whatami.JavaMenu" > </activity>
Related
I have created a splash activity for my app. I am trying to redirect from my Splash activity to the Starting Point activity using AndroidManifest.xml but its not working. The Splash class loads up, and then it doesn't redirect to the Starting Point. And it doesn't give any errors either.
So can you please help me figure it out.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
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.example.myapp.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="com.example.myapp.StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myapp.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Now I have also tried
<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>
<activity
android:name=".StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myapp.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
So what can I do here. I am not getting redirected from Splash to my Starting Point.
Splash Code
package com.example.myapp;
import android.app.Activity;
import android.os.Bundle;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
}
}
Add this code to your Splash.java
Thread timer = new Thread(){
public void run(){
try {
sleep(2000);
} catch (Exception e) {
// TODO: handle exception
} finally{
Intent i = new Intent(Flash_Activity.this, StartingPoint.class);
startActivity(i);
}
}
};
timer.start();
}
You are never calling anything to change the activity from your splash to the starting point. This thread will do that.
Use this easy way to redirect to acitvity
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
finish();
}
},2500);
I am new here,posting my first question.So this android project about showing a layout onclick of button,isn't running.When I run it,the emulator opens but my project isn't visible on it. I am trying to show another layout when button is clicked.Can anyone help me out?
My layouts are :activity_main,tutorial1 (layout to be showed after button:tutorial1 is clicked),splash(which is showed for 5 seconds on opening).
Also manja is name of sound that is played on opening,for 5 seconds.
Here's my code:
MainActivity.java:
package com.example.thebasics;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
MediaPlayer logoMusic;
#Override
protected void onCreate(Bundle AmanIsAwesome) {
super.onCreate(AmanIsAwesome);
setContentView(R.layout.splash);
logoMusic = MediaPlayer.create(MainActivity.this, R.raw.manja);
logoMusic.start();
Thread logoTimer= new Thread (){
public void run (){
try{
sleep(5000);
Intent menuIntent=new Intent("com.example.thebasics.MENU");
startActivity(menuIntent);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
};
logoTimer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
logoMusic.release();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Menu.java:
package com.example.thebasics;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class menu extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button tut1 = (Button) findViewById(R.id.tutorial1);
tut1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent ("com.example.thebasics.TUTORIAL"));
}
});
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
Tutorial.java:
package com.example.thebasics;
import android.app.Activity;
import android.os.Bundle;
public class Tutorial extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial1);
}
}
}
The basics androidmanifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.thebasics"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/download"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.thebasics.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.thebasics.MENU"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.thebasics.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.thebasics.TUTORIAL"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.thebasics.TUTORIAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Also the console is showing the error:- Emulator[ Warning: No DNS servers found]
whats this?
I have uploaded a fully working of your project.Download it from here.Also use Intent as other people mentioned.
Intent intent = new Intent(MainActivity.this or getApplicationContext(), Tutorial.class);
/* First argument is your current activity.You can also mention it i.e CurrentActivity.this */
/* Second argument is the class where you wanna go i.e OtherActivity.class */
startActivity(intent);
Use this instead :
startActivity(new Intent (context, Tutorial.class));
Your way of doing it is strange too :
dont do this :
<activity
android:name="com.example.thebasics.TUTORIAL"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.thebasics.TUTORIAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Just do :
<activity
android:name="com.example.thebasics.Tutorial"
android:label="#string/app_name" >
</activity>
Same thing for the other one.
This doesn't exist :
<action android:name="com.example.thebasics.TUTORIAL" />
This line code
new Intent ("com.example.thebasics.TUTORIAL")
Creates intent with action name "com.example.thebasics.TUTORIAL"
What you want is:
startActivity(new Intent (MainActivity.this, Tutorial.class));
Just like Tsunaze suggested.
do as follow
Intent intent = new Intent(context, Tutorial.class);
// set some flags here according to your need
startActivity(intent);
Intent intent = new Intent(context, Menu.class);
// set some flags here according to your need
startActivity(intent);
and remove this from your manifest file as this is wrong
<intent-filter>
<action android:name="com.example.thebasics.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.example.thebasics.TUTORIAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
My new android app can download from the playstore but doesn't appear in my downloaded apps. When i download it from the play store usually there is an option to 'open' the app aswell as 'uninstall', only the uninstall button is visible. (http://i.imgur.com/jNTvJq2.png notice the missing open button)
here's the my manifest, there were no errors during all the tests i ran.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jackattackapps.bigl"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/iconimage"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" >
<activity
android:name="com.jackattackapps.bigl.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.jackattackapps.bigl.Splashscreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SPLASHSCREEN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
And this is the activity that is supposed to load on the start of the application.
package com.jackattackapps.bigl;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splashscreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
Thread timer = new Thread(){
public void run(){
try{
MediaPlayer ourSong = MediaPlayer.create(Splashscreen.this, R.raw.splashsound);
ourSong.start();
sleep(2300);
}
catch (InterruptedException e){
e.printStackTrace();
} finally {
Intent openMainActivity = new Intent("android.intent.action.MAINACTIVITY");
startActivity(openMainActivity);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
if more information is needed just comment, help would be appreciated greatly.
Your Launcher activity should have this Intent Filter
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
I'm trying to create a splash screen for my app in android but it will not show up at all.
The code i'm using is 4 different files. Here it is:
Splash.java
package com.timchecklist;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread Timer = new Thread() {
public void run() {
try {
sleep(3000);
startActivity(new Intent("com.timchecklist.SPLASHNEW"));
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
finish();
}
}
};
Timer.start();
}
}
SplashNew.java
package com.timchecklist;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class SplashNew extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
}
}
Splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/pic1"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timchecklist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TimCheckListActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name=".SplashNew"
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>
Please tell me what I'm doing wrong here. Any help would be appreciated. Thanks guys:)
i think Splash should be launcher activity first . and where you declare SPLASHNEW in AndroidManifest File ?.
See Splash Screen Example
You should add SplashNew in Manifest file.
Try below code
setContentView(R.layout.splash);
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(2000);
startActivity(new Intent(getApplicationContext(),EquipmentCategory.class));
finish();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
There is no entry of SplashNew in menifest file ......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timchecklist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TimCheckListActivity"
android:label="#string/app_name" >
</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>
There is better way to make a splash screen.
Declare an handler like this, which call the next activity to launch after a precised time:
private Handler splashHandler = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
Intent intent = new Intent(Splash.this, OtherActivity.class);
startActivity(intent);
finish();
break;
}
super.handleMessage(msg);
}
};
Then execute the code after some delay like this in onCreate:
Message msg = new Message();
splashHandler.sendMessageDelayed(msg, SPLASHTIME);
When I run the splash screen without thread code the splash screen background appears
but when I launch the background image via a thread, the splash screen does not show up.
my splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/splash"
>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="travis.com"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<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>
<activity android:name=".TheNewBostonActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.thenewboston.travis.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
splash.java:
package travis.com;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle TravisLoveBeacon) {
// TODO Auto-generated method stub
super.onCreate(TravisLoveBeacon);
setContentView(travis.com.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.travis.STARTINGPOINT");
startActivity(openstatingpoint);
}
}
};
timer.run();
}
}
try to use
Thread splashTimer = new Thread() {
public void run() {
try {
sleep(5000);
// Advance to the next screen.
startActivity(new Intent(SplashActivity.this,
HomeActivity.class));//}
} catch (Exception e) {
Log.e("ex", e.toString());
} finally {
finish();
}
}
};
splashTimer.start();
try below code in your finally block:
finish();
Intent mainIntent = new Intent().setClass(Splash.this, nextscreen.class);
startActivity(mainIntent);