Tagactivity

Android Activity Lifecycle

This is very old topic. Back to 2009 – some day I promised to myself to read android javadoc method by method. I didn’t:) So even now from time to time I find interesting methods in interesting places. Like onUserLeaveHint() and onUserInteraction() in Activity (API v3).

Anyway, here is an interesting picture of complete Activity Lifecycle originally posted on G+. Just found it on reddit today.

complete android fragment activity lifecycle

http://staticfree.info/~steve/complete_android_fragment_lifecycle.png

just in case you missed it

//DL

Android: Application Context and Activity Context difference in custom adapters

When you inflate a view in your custom Android adapter (extends BaseAdapter) – you may use either Application context or your Activity context.

public CustomAdapter(Context c) {
    mInflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
// or
mInflater = (LayoutInflater)YourApplication.getAppContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

what is the difference? Both solutions are okey… until you add something like autolink to your TextView inside adapter items.

In this case if you are using Application context – you will get an exception:

03-13 16:29:09.552: ERROR/AndroidRuntime(30777): Uncaught handler: thread main exiting due to uncaught exception
03-13 16:29:09.572: ERROR/AndroidRuntime(30777): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
03-13 16:29:09.572: ERROR/AndroidRuntime(30777): at android.app.ApplicationContext.startActivity(ApplicationContext.java:649)
03-13 16:29:09.572: ERROR/AndroidRuntime(30777): at android.content.ContextWrapper.startActivity(ContextWrapper.java:248)
03-13 16:29:09.572: ERROR/AndroidRuntime(30777): at android.text.style.URLSpan.onClick(URLSpan.java:62)
03-13 16:29:09.572: ERROR/AndroidRuntime(30777): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:216)
03-13 16:29:09.572: ERROR/AndroidRuntime(30777): at android.widget.TextView.onTouchEvent(TextView.java:6528)

03-13 16:29:09.572: ERROR/AndroidRuntime(30777): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
03-13 16:29:09.572: ERROR/AndroidRuntime(30777): at dalvik.system.NativeStart.main(Native Method)

because your application needs Activity context to start web browser. simple.

//DL

© 2017 Android Tales

Theme by Anders NorenUp ↑