android-lifecycle

When Can I First Measure a View?

一世执手 提交于 2019-11-26 00:58:13
问题 So I have a bit of confusion with trying to set the background drawable of a view as it is displayed. The code relies upon knowing the height of the view, so I can\'t call it from onCreate() or onResume() , because getHeight() returns 0. onResume() seems to be the closest I can get though. Where should I put code such as the below so that the background changes upon display to the user? TextView tv = (TextView)findViewById(R.id.image_test); LayerDrawable ld = (LayerDrawable)tv.getBackground()

Difference and uses of onCreate(), onCreateView() and onActivityCreated() in fragments

此生再无相见时 提交于 2019-11-26 00:39:07
问题 What are the differences between onCreate() , onCreateView() , and onActivityCreated() in fragments and what would they each be used for? 回答1: onCreate(): The onCreate() method in a Fragment is called after the Activity 's onAttachFragment() but before that Fragment 's onCreateView() . In this method, you can assign variables, get Intent extras, and anything else that doesn't involve the View hierarchy (i.e. non-graphical initialisations). This is because this method can be called when the

How to start new activity on button click

偶尔善良 提交于 2019-11-25 22:55:42
问题 In an Android application, how do you start a new activity (GUI) when a button in another activity is clicked, and how do you pass data between these two activities? 回答1: Easy. Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class); myIntent.putExtra("key", value); //Optional parameters CurrentActivity.this.startActivity(myIntent); Extras are retrieved on the other side via: @Override protected void onCreate(Bundle savedInstanceState) { Intent intent = getIntent(); String

How do I prevent Android taking a screenshot when my app goes to the background?

只愿长相守 提交于 2019-11-25 22:49:48
问题 The app I\'m currently building has the requirement that the app has to prevent the OS to take a screenshot of the app when it\'s being pushed into the background for security reasons. This way it won\'t be able to see the last active screen when switching between apps. I\'m planning to put this functionality in the application class\'s onPause method, but first I need to find out how I can achieve this functionality. So is there anybody out there, that has a clue how to fix this? 回答1: Try

When Can I First Measure a View?

对着背影说爱祢 提交于 2019-11-25 20:49:58
So I have a bit of confusion with trying to set the background drawable of a view as it is displayed. The code relies upon knowing the height of the view, so I can't call it from onCreate() or onResume() , because getHeight() returns 0. onResume() seems to be the closest I can get though. Where should I put code such as the below so that the background changes upon display to the user? TextView tv = (TextView)findViewById(R.id.image_test); LayerDrawable ld = (LayerDrawable)tv.getBackground(); int height = tv.getHeight(); //when to call this so as not to get 0? int topInset = height / 2; ld