I have one Application named Application A, while installing Application A, I want to Open Activity A and While Clicking launcher icon I want to open Activity B. Is this possible? Can anyone help on this?. Thank you.
You can achieve that with SharedPreferences. Use a boolean, at first run you will have to set that boolean to true and it will be saved locally on your phone. Inside your MainActivity or your Application class(if you have one), do a check and start Activity A if boolean is false otherwise start Activity B.
Related
I have an android app chat. It has to be secure so I want to force my app to open always at Main Activity. This doesn't happen when I click the history of launcher, it opens the activity shown on launcher history not the main activity. How can I force it open the Main Activity always?
android:clearTaskOnLaunch="true"
I have this on Manifest but doesn't work.
that seems right and it should work but this option is a bit buggy when you build the app directly to the device, please try to install the apk manually
I offer you another way.
Look at the Application.ActivityLifecycleCallbacks, namely on :
onActivityPaused
onActivityResumed
onActivityCreated
When application was closed with HOME button or launch from recent task, you may have determine a boolean value that can be saved in SharedPreferences
boolean isSecure = false;
When activity paused - isSecure -> true -> save into sp.
When activity resumed\paused - read from sp -> isSecure = sp.getBoolean(...,false);
I have an application which has two activities A and B. When application is installed and run for the first time then it always starts with A as it is declared as launcher activity in manifest.
According to workflow, after a few seconds, activity A is destroyed and activity B is started. So that, the root of task becomes B. Now, when user presses the home button and later comes to our app, activity B is resumed as expected. But, if application is left in background for a long time then the application is restarted as from the logs Application::onCreate() is called. However, I want that whenever the application restarts that is whenever Application::onCreate() is called (like in the second case) activity A should be started instead of B, in all other cases when application is not restarted activity B should be appearing. I am new to android and unable to figure out a solution. Any help is much appreciated.
Thanks in advance.
Use SharedPreferences : http://developer.android.com/reference/android/content/SharedPreferences.html
In the end of your activity A you should create a preference that save the a state of your app in the SharedPreference.
at the start of onCreate() of your activities check the state and start the correct activity.
I have an issue with my Robotium tests. On one of my Activity A, I am clicking on a button. Clicking on this button launches another activity B. So in my robotium test I have something like this :
Button myBtn = (Button) solo.getView(R.id.myBtn);
so after this action, the emulator is automatically launching activity B. Now, the problem is that I do not have any possibility of going back to the activity under test (A) in the code.
Can you please tell me how to avoid getting jailed in the activity B when clicking on the button that trigger its launch ? In other words, is it possible to go back to the activity under test ?
FYI : I need to go back to the activity under test because there are other test methods waiting to be fired.
thanks in advance,
Please try methods like
solo.clickOnView(R.id.myBtn)
to click on your button
You can also try
solo.clickOnButton()
To go back to activity you can use
solo.goBack();
or
solo.goBackToActivity("ActivityName");
Once you call any activity outside your application, it’s not possible to come back to your application using solo.<any API>, because solo is tight to UID of your application and doesn't work on other app's activity (with different UID).
Basically solo can only work on activities which belong to the application for which it’s created.
hi all
i have an app with 3 activity. if i launch the app the first time it have to redirect to second activity from first activity. after the first time launch the app it have to go to third activity from first activity. how to do that? please help me. is there way to without using database?
Set a boolean flag in the SharedPreferences. On loading your application you can read that flag.
If it is null: goto Activity 2 and set the flag to true
If it exists: goto Activity 3
I am developing an application where one of my Activity contains a button as "Set as Home Page".
So my problem is that when I will click this button the status will be saved in the shared preference and next time when this application will be opened I want to start this Activity (the Activity which has been set as home page) instead of the default one.
So how can i do it???
You need to have defined static constant unique ID for each of your Activity. You save this ID to shared preferences, and implement on your boot activity's onCreate event a switch based on this stored ID against the static constant ID of your Activity. When you have the right step start the activity, and finish your current activity the booter.
You could create a kind of redirection Activity on which your application would start on. Then, put a switch in this activity, with intents sending to each of your activities, and the state of the preference would be the variable to test for the switch.
I'm not sure I'm clear but tell me if it's fine for you?