I am new to android development, and I'm trying to add a splash screen in my app.
I found this tutorial:
I have added the files as mentioned in the tutorial but it doesn't seems to work, there is an error in my Splashscreen.java file
It gives me the error cannot resolve symbol androidmkab
Thanks for helping in advance.
Splashscreen.java
package com.myapplication;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.ImageView;
import com.androidmkab.randomsplash.MainActivity;
import java.util.Random;
public class Splashscreen extends Activity {
Thread splashTread;
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
imageView = (ImageView)findViewById(R.id.imageView2);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
int[] ids = new int[]{R.drawable.s_img,R.drawable.s_image_black, R.drawable.s_image_black2};
Random randomGenerator = new Random();
int r= randomGenerator.nextInt(ids.length);
this.imageView.setImageDrawable(getResources().getDrawable(ids[r]));
splashTread = new Thread() {
#Override
public void run() {
try {
int waited = 0;
// Splash screen pause time
while (waited < 3500) {
sleep(100);
waited += 100;
}
Intent intent = new Intent(Splashscreen.this,
MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
Splashscreen.this.finish();
} catch (InterruptedException e) {
// do nothing
} finally {
Splashscreen.this.finish();
}
}
};
splashTread.start();
}
}
activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:layout_gravity="center"
android:id="#+id/lin_lay"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/splash"
android:background="#drawable/logo" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Splashscreen"
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"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
import com.androidmkab.randomsplash.MainActivity; remove this line from the top. Its not your package... instead make it import com.myapplication.MainActivity
the problem seems to be that you are trying to call a package which does not exist in your project. androidmkab.randomsplash.MainActivity should be replaced with your project package. such as com.myApplication.MainActivity
Delete the line com.androidmkab.randomsplash.MainActivity; and write com.myapplication.MainActivity;
Related
I am trying to apply animations to my project, when I set the interpolator to:
alpha.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/bounce_interpolator">
<alpha android:fromAlpha="0"
android:toAlpha="1"
android:duration="4000"
/>
</set>
SplashActivity.java:
package com.example.animationtesting;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
public class SplashActivity extends AppCompatActivity {
ImageView imageView;
TextView textView;
Animation alpha;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
imageView = findViewById(R.id.imageView);
textView = findViewById(R.id.textView);
alpha = AnimationUtils.loadAnimation(this,R.anim.alpha);
imageView.setAnimation(alpha);
textView.setAnimation(alpha);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
},4000);
}
}
Android Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AnimationTesting"
tools:targetApi="31">
<activity
android:name=".SplashActivity"
android:exported="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
The code is working fine when I set the interpolator as bounce_interpolator, accelerate_interpolator, anticipate_overshoot_interpolator but when I set the interpolator to other options like fade_in, fade_out,slide_out_right my app crashes. I don't get why this is happening.
First I thought your app crashed because you try to put the animation on two different xml-objects, but then I replicated the entire thing using this guide and for me, everything is working. (Although I did it using Kotlin).
I'm sorry, the only solution I could provide was this URL to the guide, but if you have any more questions, feel free to ask!
already performed clean project, rebuild project, analysed and inspected code but it does not resolve the issue. This started when making "Slash Screen" i check my XML files it looks good to me, but started to realize in every .Java class i created symbol R. was underlined with red try everything i can think of....
`package com.example.dom.myapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splashscreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread() {
public void run() {
try
{
sleep(4000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent myactivity = new Intent("com.example.dom.MAINACTIVITY");
startActivity(myactivity);
}
}
};
timer.start();
}
}`
Here's my Splash layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/front"
>
</LinearLayout>
Here's my LogCat
04-27 18:27:49.869 12888-12888/? E/Zygote: MountEmulatedStorage()
04-27 18:27:49.869 12888-12888/? E/Zygote: v2
04-27 18:27:49.879 12888-12888/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
04-27 18:27:55.679 12888-12945/com.example.dom.myapp E/OpenGLRenderer: SFEffectCache:clear(), mSize = 0
Here's my AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dom.myapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".ActivityOne"></activity>
<activity android:name=".ActivityTwo"></activity>
<activity android:name=".ActivityThree"></activity>
<activity android:name=".ActivityFour"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
In splash layout do this
android:background="#+id/drawable/front" must be android:background="#drawable/front" remove this #+id/
looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/front"
>
</LinearLayout>
i am trying to get a sound file to play when my splash screen is showing on my android app.... i have been trying to figure it out for a few hours now..... when i run my app it just skips the splash sreen all together now
here is my SplashScreen.java
package com.skapaidbeats.app.skapaidbeats;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import com.skapaidbeats.app.skapaidbeats.MainActivity;
import com.skapaidbeats.app.skapaidbeats.R;
public class SplashScreen extends Activity {
MediaPlayer music;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timerThread = new Thread(){
public void run(){
try{
music= MediaPlayer.create(SplashScreen.this, R.raw.sound);
music.start();
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(SplashScreen.this,MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
music.release();
finish();
}
}
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
package="com.skapaidbeats.app.skapaidbeats">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreen"
android:screenOrientation="portrait"
android:label="#string/icon_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:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.startapp.android.publish.list3d.List3DActivity"
android:theme="#android:style/Theme" />
<activity
android:name="com.startapp.android.publish.AppWallActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.Translucent" />
<activity
android:name="com.startapp.android.publish.OverlayActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#android:style/Theme.Translucent" />
<activity
android:name="com.startapp.android.publish.FullScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#android:style/Theme" />
</application>
</manifest>
Did you declare your activity in the manifest?
If you did, this question was asked before, try the following:
Android Sound not playing in splash screen
How to play audio in splash screen in android
You can try this
MediaPlayer player = new MediaPlayer();
player.setDataSource("/sdcard/audiotrack.mp3");
player.prepare();
player.start();
I'm trying to play an video on my android app, but when I click on the activity through my menu list, the app stays on the list and doesn't play the video.
The code is below
my menu
package com.example.taekwondobuddy.util;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Kicks extends ListActivity {
String classes[] = {"FrontKick","RoundhouseKick","AxeKick"} ;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Kicks.this, android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
try{
Class ourclass = Class.forName("com.example.taekwondobuddy.util" + cheese);
Intent ourIntent = new Intent(Kicks.this, ourclass);
startActivity(ourIntent);
} catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
the video I'm trying to play
package com.example.taekwondobuddy.util;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class RoundhouseKick extends Activity {
private VideoView mVideoView;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.roundhousekick);
mVideoView = (VideoView) findViewById(R.id.roundhousekick);
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.roundhousekick));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
the xml layout
<?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">
<VideoView
android:id="#+id/roundhousekick"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
and the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.taekwondobuddy.util"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.taekwondobuddy.util.Menu"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Tools"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Techniques"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Kicks"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Counter"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Time"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Accelermeter"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.FrontKick"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.RoundhouseKick"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.AxeKick"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
</application>
</manifest>
I think it something wrong with the manifest but I can't really see what's wrong, any ideas? Plus the video are in mp4 so they're are in the right format for android
I think, you just missed one little thing: a dot (.)
See at your code here:
Class ourclass = Class.forName("com.example.taekwondobuddy.util" + cheese);
don't you think it should be like this:
Class ourclass = Class.forName("com.example.taekwondobuddy.util." + cheese);
Try to use:
mVideoView.start();
I know I already asked this, but I didn't get a sufficient answer. Im trying to start an activity, but the emulator stays on the first activity. Ive tried all ways to do it but it never works. The youtube videos show that it should work but it never does. Is there something missing or is there anything wrong with the following code?
//First Activity:
package com.mtprogramming.magicsquaresgame;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
public class Opening extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opening);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
Intent open = new Intent("com.mtprogramming.magicsquaresgame.MENU");
startActivity(open);
}
}
};
timer.start();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.opening, menu);
return true;
}
}
//Second Activity:
package com.mtprogramming.magicsquaresgame;
import android.app.Activity;
import android.os.Bundle;
//Created by suprav on 7/11/13.
public class Menu extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
}
}
//Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mtprogramming.magicsquaresgame"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.mtprogramming.magicsquaresgame.Opening"
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.mtprogramming.magicsquaresgame.Menu"
android:label="#string/title_activity_menu"
android:parentActivityName="Opening" >
<intent-filter>
<action android:name="com.mtprogramming.magicsquaresgame.MENU"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="Opening" />
</activity>
</application>
</manifest>
Try this:
Intent open = new Intent(Opening.this, Menu.class);
startActivity(open);
I think i found the issue, seems like metadata property is not being properly used, hences activity its not being started, this is the proper way to use the property:
<activity android:name=".TestActivity" >
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value=".TestParentActivity">
</meta-data>
</activity>
So, seems like you are missing a dot in "android:value="Opening"
Regards!