Error in Context in Android? -
i wrote simple 1 line context of application in android.
there nothing else except new project 1 activity.
i wrote code in oncreate method.
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); context context = getcontext(); }
it asks me replace getcontext getbasecontext.
why can't use getcontext present?
please make understanding clear on android context-
getcontext() or view.getcontext(): returns context view running in, through can access current theme, resources, etc.
getapplicationcontext() or activity.getapplicationcontext(): application context associated applicaition , same throughout life cycle.
context.getbasecontext():should not used use context instead of associated activity , possible destroyed when activity destroyed.
and please have on this blog-post avoid android context related memory leak problem.
(you may come across many need choose fit need)
Comments
Post a Comment