Search code examples
androidandroid-activitycrouton

Android: Crouton + Activities state


I'm using Crouton im my project.In app i have few activities. In sub activities i want do some operations after finishing a process i make redirect to main activity and display Crouton message about result in previous activity. But hier i have problems...Crouton closes quickly after redirect. I found some solution:

1) Create intent for sub activity 2) close main activity 3) start sub activity

do some work...

4) Create intent for main activity 5) Put info in extra about changes 5) open main activity

and in main activity, in onCreate, i trying get extra about changes. I tried get info from extra in onStart, onResume..but still the same..Crouton message closes quickly, faster than needed.

What i am doing wrong? Maybe my algorithm with displaying Crouton is wrong..Pls correct me.

Thx a lot!


Solution

  • I found solution to my question:

    @Override
        protected void onResume() {
            super.onResume();
    
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    displayEvents();
                }
            }, 500);
    
        }
    
    private void displayEvents(){
    
            //Проверяю какое уведомление необходимо показать
            if(intent.hasExtra("event")){
    
                if(intent.hasExtra("event") && intent.getStringExtra("eventType").equals("confirm")) {
    
                    Crouton.makeText(MainActivity.this, intent.getStringExtra("event"), Style.CONFIRM).show();
                    getIntent().removeExtra("event");
                    getIntent().removeExtra("eventType");
    
                }
    
            }
    
        }
    

    done!