"Client not ready yet" when adding splashscreenactivity - android

I want to add a splashscreen activity to my app.
I'm using Android Studio 2.2, Preview 3
I just modify my manifest, to add in the new activity :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.youactive.hts.youactive">
<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"
android:label="YouactiveSlidingMenu"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".SplashScreenActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
and here is my SplashScreenActivity.java
package me.youactive.hts.youactive;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SplashScreenActivity extends AppCompatActivity
{
private final int SPLASH_DISPLAY_LENGTH = 3000;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
}
#Override
protected void onResume()
{
super.onResume();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
// Obtain the sharedPreference, default to true if not available
boolean isSplashEnabled = sp.getBoolean("isSplashEnabled", true);
if (isSplashEnabled)
{
new Handler().postDelayed(new Runnable()
{
#Override
public void run()
{
//Finish the splash activity so it can't be returned to.
SplashScreenActivity.this.finish();
// Create an Intent that will start the main activity.
Intent mainIntent = new Intent(SplashScreenActivity.this, MainActivity.class);
SplashScreenActivity.this.startActivity(mainIntent);
}
}, 3000);
}
else
{
// if the splash is not enabled, then finish the activity immediately and go to main.
finish();
Intent mainIntent = new Intent(SplashScreenActivity.this, MainActivity.class);
SplashScreenActivity.this.startActivity(mainIntent);
}
}
}
If I change my manifest, and put the arround MainActivity, the application launches successfull
In my Run windows,I can see this message :
adb shell am start -n "me.project.com.project/me.project.com.project.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..
I had read in some similar question in SO that adding "android:exported="true" in in Manifest could resolve this problem, but it won't in my case.

Your wifi connectivity could be reason for this error.
It might be a good idea to reconnect to your wifi before making any code related changes.

Related

My App keeps taking me back to signup page even after it checks if the user is logged in

I have added the splash screen to launch every time the app starts or even gets killed , then splash screen checks for the user if is logged in but unfortunately it directs me to the mainactivity but then later if takes me back to signup page after some couple of seconds and am not getting any error what am i missing here fellaz thanks alot
Hereis my Manifest
```
<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="com.univibezstudios.ocappservice.ocapp.signuppage"/>
<activity android:name="com.univibezstudios.ocappservice.ocapp.LoginScreen" />
<activity android:name="com.univibezstudios.ocappservice.ocapp.MainActivity" />
<activity android:name="com.univibezstudios.ocappservice.ocapp.MainActivityCenterofInformation"/>
<activity android:name="com.univibezstudios.ocappservice.ocapp.MainActivityAEA"/>
<activity android:name="com.univibezstudios.ocappservice.ocapp.MainActivitySNAL"/>
<activity android:name="com.univibezstudios.ocappservice.ocapp.MainActivityBvm"/>
<activity android:name="com.univibezstudios.ocappservice.ocapp.MainActivityForest"/>
<activity android:name="com.univibezstudios.ocappservice.ocapp.MainActivitySocial"/>
<activity android:name="com.univibezstudios.ocappservice.ocapp.MainActivityCollegeofAgriculture"/>
<activity android:name="com.univibezstudios.ocappservice.ocapp.IntroActivity"/>
<activity android:name="com.univibezstudios.ocappservice.ocapp.WelcomeScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>```
Here is my welcomescreen as the splash screen
```package com.univibezstudios.ocappservice.ocapp;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.firebase.ui.auth.data.model.User;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.univibezstudios.ocappservice.ocapp.WelcomeScreen;
public class WelcomeScreen extends AppCompatActivity {
private ImageView logo;
private static int SPLASH_TIME_OUT = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setFullscreen ();
setContentView (R.layout.welcomescreen);
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance ();
FirebaseUser firebaseUser = firebaseAuth.getCurrentUser ();
if(firebaseUser != null)
{
startActivity (new Intent (WelcomeScreen.this
, MainActivity.class));
}
logo= findViewById (R.id.logoocaap);
Animation animation = AnimationUtils.loadAnimation (this,R.anim.splashscreen);
logo.startAnimation (animation);
new Handler ().postDelayed (new Runnable () {
#Override
public void run() {
Intent intent = new Intent (WelcomeScreen.this,IntroActivity.class);
startActivity (intent);
finish ();
}
},SPLASH_TIME_OUT);
}
private void setFullscreen(){
requestWindowFeature (Window.FEATURE_NO_TITLE);
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}```
Your Handler is still running after going to MainActivity and it triggers Introactivity. .There are many ways to do it but my suggestion would be to add your Firebase's user checking condition in Handler.
Remove the firebase's user check from above and put it in Handler's run method.
new Handler ().postDelayed (new Runnable () {
#Override
public void run() {
if(firebaseUser != null) {
startActivity (new Intent (WelcomeScreen.this
, MainActivity.class));
finish ();
} else {
Intent intent = new Intent (WelcomeScreen.this,IntroActivity.class);
startActivity (intent);
finish ();
}
}
},SPLASH_TIME_OUT);
Add below code in else condition of firebase user != Null
new Handler ().postDelayed (new Runnable () { #Override public void run() { Intent intent = new Intent (WelcomeScreen.this,IntroActivity.class); startActivity (intent); finish (); } },SPLASH_TIME_OUT)

activity does not open on event detection

I am following this answer to implement app un-install detector. I am basically trying to open Main Activity when un-installation event is detected, but when I un-istall my app nothing happens (Main Activity does not open before un-install).
Please help, what is wrong with my code?
MainAcivity:
package com.example.appdeveloper.unistalltest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Broadcast Receiver:
package com.example.appdeveloper.unistalltest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class UninstallIntentReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// fetching package names from extras
String[] packageNames = intent.getStringArrayExtra("android.intent.extra.PACKAGES");
if(packageNames!=null){
for(String packageName: packageNames){
if(packageName!=null && packageName.equals("com.example.appdeveloper.unistalltest")){
// User has selected our application under the Manage Apps settings
// now initiating background thread to watch for activity
new ListenActivities(context).start();
}
}
}
else {
Toast.makeText(context, "No package found in Broadcast Receiver", Toast.LENGTH_LONG).show();
}
}
}
ListenActivities.java:
package com.example.appdeveloper.unistalltest;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import java.util.List;
public class ListenActivities extends Thread {
boolean exit = false;
ActivityManager am = null;
Context context = null;
public ListenActivities(Context con){
context = con;
am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
}
public void run(){
Looper.prepare();
while(!exit){
// get the info from the currently running task
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(MAX_PRIORITY);
String activityName = taskInfo.get(0).topActivity.getClassName();
Log.d("topActivity", "CURRENT Activity ::"
+ activityName);
if (activityName.equals("com.android.packageinstaller.UninstallerActivity")) {
// User has clicked on the Uninstall button under the Manage Apps settings
//do whatever pre-uninstallation task you want to perform here
// show dialogue or start another activity or database operations etc..etc..
context.startActivity(new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
exit = true;
Toast.makeText(context, "Done with preuninstallation tasks... Exiting Now", Toast.LENGTH_LONG).show();
}
else if(activityName.equals("com.android.settings.ManageApplications")) {
// back button was pressed and the user has been taken back to Manage Applications window
// we should close the activity monitoring now
exit=true;
}
}
Looper.loop();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appdeveloper.unistalltest">
<uses-permission android:name="android.permission.GET_TASKS"/>
<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.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".UninstallIntentReceiver">
<intent-filter android:priority="0">
<action android:name="android.intent.action.QUERY_PACKAGE_RESTART" />
<data android:scheme="package" />
</intent-filter>
</receiver>
</application>
</manifest>
Your app can't know when the user uninstall it since Android 4.0+. I had a similar problem, but didn't found a way to do it. The only things I found today (i already gave up with my app, but maybe it can help you) is this: https://developer.android.com/guide/topics/admin/device-admin.html
I'm not sure this will help you, but it is the only thing i found.

Launch login activity instead of MainActivity if app is on its first run

I need my app to check if it's running for first time or not. If it's the first time, then it should launch LoginActivity instead of MainActivity. And if it's not the first run, it should display MainActivity as usual.
I used SharedPreference value to check if it's available, then app decides its not running it's first run.
This is what I've tried so far
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set default values into settings
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
// Check if the app is running on its first run
SharedPreferences fRun = getPreferences(MODE_PRIVATE);
if(fRun.getBoolean("firstrun", true)){
SharedPreferences.Editor editX=fRun.edit();
editX.putBoolean("firstrun", false);
editX.apply();
// Login activity stuff here
// Goto login screen
Intent loginIntent=new Intent(getApplicationContext(),LoginActivity.class);
startActivity(loginIntent);
//finish();
} else {
setContentView(R.layout.activity_main);
}
}
}
My problem is, when I run my app, it suddenly crashes and displays message Unfortunately, the app has stopped.
Why does the app crash? Is it because code in my LoginActivity have errors or do I need to first load MainActivity then call LoginActivity?
You can use LoginActivity as LAUNCHER activty and check whether the user is logged in. If yes, start MainActivity.
The AndroidManifest.xml:
<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=".MainActivity"/>
And the LoginActivity:
public class LoginActivity extends ActionBarActivity {
private static final String LOGIN_KEY = "LOGIN_KEY";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences pref = getPreferences(Context.MODE_PRIVATE);
if (pref.getBoolean(LOGIN_KEY, false)) {
//has login
startActivity(new Intent(this, MainActivity.class));
//must finish this activity (the login activity will not be shown when click back in main activity)
finish();
}
else {
// Mark login
pref.edit().putBoolean(LOGIN_KEY, true).apply();
// Do something
}
}
}
The MainActivity:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Do something
}
}
<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"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".Activity.MainActivity" />
<activity android:name=".Activity.SignupActivity" />
<activity android:name=".Activity.SigninActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
You need to rearrange your Activity classes a bit I think. It's very simple to decide if your application has run first time or not and launch some Activity based on this decision. I would like to suggest the following architecture.
You can set a LauncherActivity to decide whether you need to start LoginActivity or MainActivity like this:
public class LauncherActivity extends Activity {
private boolean firstLaunch = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i;
SharedPreferences pref = getSharedPreferences(Constants.ApplicationTag, MODE_PRIVATE);
firstLaunch = pref.getBoolean(Constants.FIRST_LAUNCH, true);
if (firstLaunch) {
i = new Intent(LauncherActivity.this, LoginActivity.class);
startActivity(i);
} else {
i = new Intent(LauncherActivity.this, MainActivity.class);
startActivity(i);
}
finish();
}
}
You have another problem I need to sort out is calling setContentView inside an else statement which is erroneous. You need to put setContentView just after the super.onCreate(savedInstanceState); in any of your Activity.
When you're putting it inside an else statement, the content view may not be set which will cause an application crash.
So remove the checking for first run from MainActivity and move that portion to LauncherActivity which will solve the problem.
The AndroidManifest.xml of the LauncherActivity may look like this
<activity
android:name=".Activities.LauncherActivity"
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.LAUNCHER" />
</intent-filter>
</activity>

Not able to change application's launching activity - Android

I am not able to change starting activity of application. In starting my starting activity was com.example.image_changer.MainActivity and with this my application run correctly. Then I change my launching activity from MainActivity to com.example.image_changer.Splash. But my application not launching com.example.image_changer.Splash activity.I want com.example.image_changer.Splash as starting activity of my application.
I have tried these solutions:
1. In eclipse, I change this setting: Run menu-->Debug Configuration---->Under my app--->Android tab--->Launch Action---->Launch(radio button)---->select(from drop down menu)--->com.example.image_changer.Splash.
2. Internet search:
I have tried all solution given on this link: Change application's starting activity
In this link zeh (user) post comment, which is possibly look like same as my problem but nobody post better solution regarding this.
Note-When I run my program then it runs splash.java but not show on emulator screen, I know this because I code System.out.println(); in thread in splash.java and it print string every time in console when I run my app.
So how to solve this problem?
This is my manifest:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/imagechanger"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.image_changer.Splash"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.image_changer.MainActivity1"></activity>
<activity android:name="com.example.image_changer.GamesFragment"></activity>
<activity android:name="com.example.image_changer.MoviesFragment"></activity>
<activity android:name="com.example.image_changer.TabsPagerAdapter"></activity>
<activity android:name="com.example.image_changer.TopRatedFragment"></activity>
<activity android:name="com.example.image_changer.Imageswipe"></activity>
<activity android:name="com.example.image_changer.Mapview"></activity>
<activity
android:name="com.example.image_changer.MainActivity"
android:label="#string/app_name"></activity>
</application>
</manifest>
This is my Splash.java class file
package com.example.image_changer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
public class Splash extends Activity {
/** Called when the activity is first created. */
private Thread mSplashThread;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
final Splash sPlashScreen = this;
// The thread to wait for splash screen events
mSplashThread = new Thread(){
#Override
public void run(){
try {
synchronized(this){
// Wait given period of time or exit on touch
wait(2500);
}
}
catch(InterruptedException ex){
}
// Run next activity
Intent intent = new Intent();
intent.setClass(sPlashScreen,MainActivity.class);
System.out.println("your are in the intent");
startActivity(intent);
finish();
}
};
mSplashThread.start();
}
/**
* Processes splash screen touch events
*/
#Override
public boolean onTouchEvent(MotionEvent evt)
{
if(evt.getAction() == MotionEvent.ACTION_DOWN)
{
synchronized(mSplashThread){
mSplashThread.notifyAll();
}
}
return true;
}
}
Update your thread code to this.
new Handler().postDelayed(new Runnable() {
public void run() {
// Run next activity
Intent intent = new Intent();
intent.setClass(sPlashScreen,MainActivity.class);
System.out.println("your are in the intent");
startActivity(intent);
finish();
}
}, 2500);

when service opens an activity, second instance of app creates

im working on app that require launch app from a service.
my problem is service create new instance of app Although my app is not closed. i want just one instance.
i find this question here like my problem but i can't use Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
cause my apps crashes.
i change my tabactivity(main activity) to
android:launchMode="singleTop"
but problem still remains.
would some one guid me. thank you very much
this is my service:
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class MyAlarmService extends Service {
#Override
public void onCreate() {
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onDestroy() {
super.onDestroy();
}
#Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
openActivity(AlertActivity.class);
Log.i("LOG", "service started");
}
#Override
public boolean onUnbind(Intent intent) {
return super.onUnbind(intent);
}
public void openActivity(Class activity) {
Intent i = new Intent(getBaseContext(), activity);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
}
and this is my manifest:
<application
android:icon="#drawable/drink1"
android:label="#string/app_name"
android:name=".G"
>
<activity
android:label="#string/app_name"
android:name=".MainTabActivity"
android:launchMode="singleTop" >
<!-- it cause to just one instance of app be exist -->
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AlertActivity" android:theme="#style/Theme.Transparent">
</activity>
<activity android:name=".DrinkoflifeActivity"
></activity>
<activity android:name=".SettingsActivity">
</activity>
<activity android:name=".StaticActivity">
</activity>
<activity android:name=".ContactUsActivity"></activity>
<activity android:name="org.achartengine.GraphicalActivity"/>
<activity android:name=".DataActivity">
</activity>
<activity android:name=".LogoActivity"></activity>
<activity android:name=".SplashActivity">
</activity>
<service android:name=".MyAlarmService" />
</application>
Setting launchMode="singleTop" on your MainActivity is probably not necessary and isn't going to help you here.
When your service starts AlertActivity, it will create a new instance of that activity. If your application has an active task, this will also result in the active task being brought to the foreground and the new instance of AlertActivity will be created on top of any other activities in the task. In a comment you wrote that AlertActivity leads to MainActivity then the problem is in how you are starting the MainActivity from the AlertActivity.
You should probably start the MainActivity from the AlertActivity this way:
Intent intent = new Intent(this,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
Assuming that the MainActivity is the root activity in the task and there is still an active instance (ie: it has not yet been finished), this code will remove any other activities from the task stack and go back to the existing instance of MainActivity.

Categories

Resources