Arrange activities in android studio - java

I have a splash screen in my project it opens first with intent filter. After that it opens the main activity. But i created new activity that should be opened next to splash screen how to do that?
I have created three activities for example splash screen, main activity, login screen, Splash screen first opens next to that i need to open the login screen next only main activity.
xml code
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#mipmap/ic_main"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_main_round"
android:supportsRtl="true"
android:theme="#style/Theme.WeatherApp">
<activity
android:name=".SplashScreen"
android:exported="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:exported="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".HomeActivity"
android:exported="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
tools:ignore="LockedOrientationActivity" />
</application>

There are few ways to achieve this. This is one of my way.
First, at your AndroidManifest.xml, make sure you make your SplashActivity becomes your launcher. Then, at the onCreate method for your SplashActivity, do some delay, checking some stuff, is this user login or not. Last, go to next activity.
<activity
android:name="company.com.ui.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

new Handler().postDelayed(
new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashScreen.this, Login.class);
finish();
}
},
4000);

Related

How to start an app on boot completed in android?

I have tried every solution on the internet. But none of them worked for me. Could you check where I am doing wrong?
Maybe it no longer works in higher Api.
Here is my broadcastReceiver class :
public class ReceiverToStartAnApp extends BroadcastReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
Toast.makeText(context, "Home Task 3 Version ", Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(context, CameraRecorderActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}
Here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hometaskversion3">
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.HomeTaskVersion3">
<activity
android:name=".ui.CameraRecorderActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".service.RecorderService" />
<receiver
android:name=".receiver.ReceiverToStartAnApp"
android:directBootAware="true"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
First of all, apps that have never been started in some way do not receive system broadcasts. So you need some activity of your app to start before you receive ACTION_BOOT_COMPLETED.
Second, as noted in the comments, it is no longer allowed to start an activity from a receiver unless some conditions are met. The preferred way to do it is to show a notification with a pending intent for the activity you need to start. This approach will be less intrusive for the user.

New to Android Studio , Splash Screen Error

I am new to Android Studio and to the OS and have been designing an application, I tried to add a splash screen to my application after creating the splash screen and adding it to my manifest file but I keep getting this error:
Could not identify launch activity: Default Activity not found Error
while Launching activity
The tutorial I followed to get the splash screen provides no insight to correcting this error.
Below is my entire manifest file if someone could correct me I would be grateful.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gui.prog">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Display" ></activity>
<activity android:name=".Signup" ></activity>
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.category.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Just copy paste file,
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"/>
<activity android:name=".Display" ></activity>
<activity android:name=".Signup" ></activity>
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.category.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
It will work, as currently it is unable to know which activity is initial one.
What I like to do for a 'SplashActivity' is set my 'MainActivity' as a regular activity, and set my 'SplashActivity' as the default activity that will begin on launch.
My AndroidManifest.xml:
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" ></activity>
Then in my SplashActivity's 'onCreate' method:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread timerThread = new Thread(){
public void run(){
try{
sleep(2000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
you cant put two intent filters in the android manifest file if you want to launch app with spalsh screen activity you have to put the intent filter in the splash activity

Android Studio Not Finding Main Activity

I created a new class in my project called UserTypeSelection.java and wanted to set it as the main activity which launches when I run the app. I've changed the manifest file to contain an intent filter and also tried editing the configurations to set it as the default activity, however I keep receiving the error:
Error running app: The activity must be exported or contain an intent-filter
My manifest file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.XXXXX.computerscienceinduction">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".UserTypeSelection" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity android:name=".RegistrationActivity"></activity>
<activity android:name=".MainActivity" />
<activity android:name=".LoginActivity" />
<activity android:name=".ProfileActivity" />
</application>
</manifest>
How can I resolve this issue. Any help is appreciated, thank you.
You are closing your activity xml tag before you have specified the IntentFilter.
Change your declaration to this.
<activity android:name=".UserTypeSelection" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
UserTypeSelection must be activity and it must be using intent filters you have not closed activity after intent filter it is closed before.
Try this,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.XXXXX.computerscienceinduction">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".UserTypeSelection">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".RegistrationActivity"/>
<activity android:name=".MainActivity" />
<activity android:name=".LoginActivity" />
<activity android:name=".ProfileActivity" />
</application>
</manifest>

Intent activity class not working

hey guys so im having a problem when trying to run the emulator of my application on android studio. this is the error im getting:
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.dre.appli/com.example.dre.appli_app.LoginActivity }
Error type 3
Error: Activity class {com.example.dre.appli/com.example.dre.appli_app.LoginActivity} does not exist.
ive tried everything that people have suggested to no avail. here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wheretas.appli_app">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".LoginActivity"
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=".CreateAccount"
android:label="#string/title_activity_create_account"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="app.createaccount" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I suppose your LoginActivity has a package com.example.dre.appli_app.LoginActivity
But your manifest's package is different:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wheretas.appli_app">
...
Try to set it com.example.dre.appli_app

Removing an Android Shortcut from Home screen

I am trying to remove a shortcut from the home screen that my app has already added. I have tried the methods in these links but I can't figure out how to adapt their solutions to my code. I dont have a rooted device so I cant find the URI.
https://codinggeekorg.wordpress.com/2011/01/31/android-home-screen-shortcuts-part-iii-remove-shortcuts/
Trying to UNINSTALL_SHORTCUT but shortcut won't go away
Android: Remove app shortcut from home screen
Here is where I create the shortcut:
protected void ShortcutCreatorActivity(String number, String message, String name) {
Intent shortcutIntent = new Intent(getApplicationContext(), ShortCutActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("number", number);
shortcutIntent.putExtra("message", message);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
This is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abezukor.autosms" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".RelativeLayoutActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".ListViewActivity"
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=".ShortCutActivity"
android:label="AutoSms">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Thanks for your help in advance.

Categories

Resources