App start up delay - android-activity

I am developing an application. The flow and the task performed in the activities of app is as follows:
1) Splash screen - A. In Async Task 1st Download a Image from server then Create data base
B. From post of Async A call Async B for Push Notification registration
C. From post of Async B call Async C to check a flag -
If flag Screen2 == 1 {
If flag Screen3 == 1{
go to screen 4
} else {
go to Screen 3
}
} else {
go to screen 2
}
2) Screen 2 - In onCreate(): A. Call some web services for registration. B. Set Flag of screen 2 completion to 1.
3) Screen 3 - In onCreate(): A. Call some web service. B. Set Flag of screen 3 completion to 1.
4) Screen 4 - This is Home Screen. In onCreate(): A. Call some web services B. Register Broadcast Receiver C. Start two services
The issue is: When i install app it runs ok. But when i close/kill app then on click of icon the app start up delays when flag Screen2 == 1. also when Screen3 == 1.
I am not getting why my application behavior is like this.
Please provide your valuable suggestions and guidance.
Thank you.

May be you are doing webservice calls synchronously in onCreate.
Any http call in onCreate should be asynchronous(use a thread or use libraries like android volley - http://developer.android.com/training/volley/index.html)

From where you are getting the flags?
If it is from database the save and retrieve it from preferences.
Call all the web services in Threads or in background.
Also start your all services in methods and do task in services in Thread or in background.
For shared preference have a look on following links:
Link 1
Link 2
Link 3
And for Background task:
Link 1
Link 2
Link 3

Related

Flutter go_router, how to get the whole current stack of pages?

Meaning if I go from a job screen to a client screen (the client the job was for), to another job screen (another job done for the client) etc, how can I display job > client > job?
And including parameters, so I could display Job 12 > SomeCompany > Job 17.
Sub routes aren't sufficient because the stack can repeat through multiple of the same pages infinitely.
I'm not sure about checking the whole stack , but in case of anybody needed to check if there is a page on the stack , GoRouter has a canPop() method:
/// Returns `true` if there is more than 1 page on the stack. bool canPop() => GoRouter.of(this).canPop();
This isn't possible with go_router. auto_route has an API to check the stack, but go_router shows no search results for stack.
Instead of GoRouter.of like in this answer, you could use the extension method BuildContext#canPop. For example, in my onboarding page, I have this logic to pop if I can, and if not possible (the first time someone launches the app), I replace the page.:
if (context.canPop()) {
context.pop();
} else {
context.replace(Routes.dashboard);
// Or alternatively, allow the user to navigate back to onboarding with:
// context.push(Routes.dashboard);
}

ionic tabscontroller make not-first active on startup

When you start an ionic application with a tabbar on the bottom, it always starts the App with the first Tab active.
But I have 3 tabs, and I want the Tab in the middle to be the active Tab that starts when I open the App.
Can't find in the docs how to do this. Someone?
There is $ionicTabsDelegate for your needs. You can inject it into any controller, or your app's run block. Then you do it similar to the example:
function MyCtrl($scope, $ionicTabsDelegate) {
//use 1 to select the second tab (starts with 0)
$ionicTabsDelegate.select(1);
}
if you want to have it when your app starts, put in in your run block

Lifecycle and Activity Stack

In the application activities are stacked like this: A - > B - > C - > D - > E.
If I receive a particular notification and click on it, Activity E is started.
If I then click back (button on phone or button on actionbar), the application exit.
How do I make the transition to Activity D in this case, and then back through C, B, and A?
My code of back button:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return true;
}
Everything is okay when starting the application normally. The problem is when Activity starts from the notification.
Android has the functionality you're after built in, and it is already well documented. To begin with you should look at the TaskStackBuilder class. It was introduced in JellyBean, but is already included in the support library, and you use it to build a synthetic TaskStack which is what you need. A summary from the documentation reads:
When crossing from one task stack to another post-Android 3.0, the application should synthesize a back stack/history for the new task so that the user may navigate out of the new task and back to the Launcher by repeated presses of the back key. Back key presses should not navigate across task stacks.
TaskStackBuilder provides a way to obey the correct conventions around cross-task navigation.
How you build it is going to depend on the relationships of the Activities in your app, but the Tasks and Back Stack developers guide is a good read to help you decide, as is the Navigating with Up and Back design guide, if this is all new to you.
You'll find some code examples in the Implementing Effective Navigation lessons, also on the Android developers site, in the training section.
Incidentally, the button on the ActionBar is referred to as Up. Even though it sometimes shares the same functionality as the back button, the two are not the same (I assume that's the one you are talking about ;-) .)
I think you can solve your problem by sending an intent from Activity E to Activity D, and so on.
Therefore you should overwrite the method
onBackPressed()
that is called when you click on the back button.

Android 4.0 issue with Activity Stack and Task Stack

I am developing an app for android 4.0. I am confuse with Task and Activity stack for Android 4.0.
suppose I have activities X,Y,Z of the same app. so when i fire Home intent with flag activity_clear_task i am navigated to home which is expected.
case I when I am in some other app's activity say setting-> manage application and if Home intent is fired from my activity i am able to navigate to home but when i click on menu i don't see any thing thing is the new task is started ?
I cant provide screenshot as m new to stack-overflow and my reputation is <10
case II when i fired home intent while i am in my aap then i am navigated to home and i am able to see the menu.which is expected.
I cant provide screenshot as m new to stackoverflow and my reputation is <10
case III follow the procedure as case I and relaunch the app using to app using long key pressed and again home intent is fired i am navigated back to home and now i can see the menus when clicked on menu
I cant provide screenshot as m new to stackoverflow and my reputation is < 10
my question here is why this is happening it works perfectly well on 3.0 and lower. is it because of new implementation of task and activity stack. i am confused. please see the above screen shots for case I and case II.
also i faced activity stack issue about the activity stack behavior in 4.0 as when i launch setting->manage application come back to home and launch contact app and go to its sub-activities and press home button and navigate back to setting now press back key until u exit setting and u'l see something strange as u are navigated to home not the contact app.
i also saw this post but there are no answers.

How to handle UI interaction from view model without user request using MVVM, PRISM, and MEF

I am working on an application which is using WPF, MVVM, Prism, and MEF.
I am using a combination of navigation with request navigate, controllers with view management using region manager, and eventing via event aggregator to run the application in a single window. I'm using a view first approach similar to how the Stock Trader RI works.
This works great when any view model code that would interact with the UI (busy indicator) is kicked off by the user, but when it is started behind the scenes there can be problems.
I know this may seem like a poor implementation, but I think I have a valid scenario. My particular example has to do with login.
Currently the application starts and loads the shell. The login view is loaded into the main content region of the shell. When the user clicks "login" a busy indicator is shown and the client application services login is executed. When the login is complete, the busy indicator goes away, and the screen is navigated to the user's home screen.
This works well because the navigation login and navigation are initiated by the user clicking the login button.
So now I have a new requirement that a user can select Auto Login on the login form, such that the next time the user starts the app, the login view will not show up and login will happen behind the scenes.
Now if I just want to call the auto login feature, there is no problem, this by itself has no UI interaction and will work fine. But login takes a few seconds and I want to display my busy indicator.
The problem is where do I initiate the auto login call? The shell view model constructor? The shell view model PartImportsSatisfied implementation? In any of these places, the shell view (which contains my busy indicator) isn't really loaded yet. As a result, none of the resources I need, like regions and region managers aren’t available.
So what might be a good way for me to implement this:
Check if previous user should auto login (got this part figured out)
If yes then
Show busy indicator
Attempt to auto login
If auto login was success
Hide busy indicator
Navigate to user home screen
Else
Hide busy indicator
Navigate to login screen
Else
Hide busy indicator
Navigate to the login screen
Any ideas are greatly appreciated.
Implement an interface within your ShellViewModel which will deal with the concept of being loadable. Do not perform this logic within the constructor of the ShellViewModel as this is typically bad practice and should be used to instantiate objects at the most.
public class ShellViewModel : ILoadable
{
public ShellViewModel()
{
}
bool ILoadable.Load()
{
//this is where you can take care of your auto login
}
}
You could then call this within your Bootstrapper class. If this were being done within another module you could call it within the IModule.Initialize method.
I would also argue that this logic should get implemented within a service which could be called by the ShellViewModel as mentioned above or could in theory be called directly from the Bootstrapper class; allowing the ShellViewModel to potentially then make use of stateful data from within the service.