android-context

How to Start an Intent for Result from a contained class of an Activity (startActivityForResult)

江枫思渺然 提交于 2020-01-15 06:51:27
问题 This is a follow up to my previous question: How to Start an Intent from a contained class of an Activity Basically, I realized that I need to call startActivityForResult (and not startActivity ) from a contained class of an Activity. The answer from the previous question passed the Context from the Activity class to the contained class. However, the context alone isn't enough to call StartActivityForResult . What is the best way to do this? Do I have to pass the entire Activity Class to the

ContextCompat.getcolor() going to null object reference

会有一股神秘感。 提交于 2020-01-14 09:37:11
问题 I'm getting error when I set color to SlidingTabLayout object. Here is my mainActivity, first I found that getResource.getColor is deprecated. So I used contextCompat.getColor. But now its going to null. public class MainActivity extends AppCompatActivity { private Toolbar toolbar; private ViewPager mPager; private SlidingTabLayout mTabs; private MyPagerAdapter adapter; Context context; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

how to use context inside the Broadcast Receiver?

孤街浪徒 提交于 2020-01-14 05:50:07
问题 I managed to create a function that returns context of an activity and I used this context inside a broadcast receiver and it does what it supposed to do, if the application is not stopped, but when I stop the application I cant get the context of the activity because it returns null value, so how can I maintain the context value to be used by the broadcast receiver even if my application gets killed ? This is the function that returns the Context object and the constructor is called inside

How to Start an Intent from a contained class of an Activity

試著忘記壹切 提交于 2020-01-13 19:36:11
问题 I'm looking for the best way to start an intent from a class that is not an Activity, but is a contained object of an Activity class. For example the Activity Class: Class MainActivity extends ListActivty { ... TestLauncher tester; } and the class that I want to start the intent from: Class TestLauncher { public TestLauncher () { //Code to create an intent needs a Context //Intent i = new Intent(Context, class) //Code to start activity needs to be called with an Activity //Activity

Failed to Fill Spinner Values From Bean Class using Java in Android?

a 夏天 提交于 2020-01-06 03:41:09
问题 public class BriefFragmentActivity extends Fragment { public BriefFragmentActivity() { } public static final String ARG_SECTION_NUMBER = "section_number"; String getParameter_Url = "parameters/getParameters"; Spinner spinnerSystemType; ArrayList<String> systemTypeArrayList; DataBaseAdapter dataBaseAdapterInstance; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.brief_fragment_view, null);

Android: determining the current context to display an alert

百般思念 提交于 2020-01-05 08:24:07
问题 I am calling the ZXing scanner from Screen-A using Intent s. Once the scan is done, control returns, of course, to the code behind Screen-A and I do some other work before calling Screen-B. Problem is: the screen is black during this work period and I cannot determine the proper context to use to display a "working..." Toast/msgbox. Any help or suggestions? 回答1: Execute your " work period " in it's own thread , while that thread works in the background Android will pass control to Screen-A

Android onChange() method only returns false

无人久伴 提交于 2020-01-05 04:37:04
问题 I have a ContentObserver onChange() declared as a subclasse in my activity. But it always returns false. Can anyone tell me why? (Update) This code must call the fillList if the CallLog content provider changes. I mean, if I make a new call, so the data of the call will be inserted in the content provider, so it must return to the observer that something has changed there, so it will call the fillList().But it always return false, even If I make a new call on the emulator. Here is the code.

Button btn = new Button(this); what is the use of “this” in this context…?

ε祈祈猫儿з 提交于 2020-01-02 13:47:15
问题 Button btn = new Button(this); btn.setText(“This is a Button”); btn.setLayoutParams(params); What will happen if we don't pass "this" as context reference to the Button....?? 回答1: Context is interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities,

Button btn = new Button(this); what is the use of “this” in this context…?

ε祈祈猫儿з 提交于 2020-01-02 13:45:21
问题 Button btn = new Button(this); btn.setText(“This is a Button”); btn.setLayoutParams(params); What will happen if we don't pass "this" as context reference to the Button....?? 回答1: Context is interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities,

Android inner classes memory leak and leak by context?

爱⌒轻易说出口 提交于 2020-01-02 10:04:16
问题 I am using Handler in my splash screen for delaying redirection to the next activity as follows.. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.entrance); screenTimeOut(); } private void screenTimeOut() { /* New Handler to start the next screen * and close this Entrance after some seconds.*/ new Handler().postDelayed(new Runnable() { @Override public void run() { initTracker(); /* Create an Intent that will start the