android-lifecycle

Android; How can I initialise state in one activity, then have another refresh that?

隐身守侯 提交于 2019-12-29 08:10:12
问题 I have two activities The first one gets some data from a content provider, and displays it The second activity has a button, and when clicked it should call the first activity to "refresh", in other words to reload data from the content provider This is my first activity ... @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.contactsview); // Grab data and put it onto screen getDataAndPutToUI(); } @Override public void

Why is my onResume being called twice?

醉酒当歌 提交于 2019-12-29 03:32:06
问题 Basically, this is what I'm doing 1) Set AlarmManager to execute BroadcastReceiver (BCR) Intent intent = new Intent(m_Context, BCR.class); intent.putExtras(extras); PendingIntent pendingIntent = PendingIntent.getBroadcast(m_Context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, StartTime, pendingIntent) 2) Start MyActivity from BCR @Override public void onReceive(Context context, Intent

save the state when back button is pressed

徘徊边缘 提交于 2019-12-28 04:08:07
问题 I am developing an android app. If I press a back button the state of my application should be saved .What should i use to save the state ..am confused with all of these onPause() , onResume() , or onRestoresavedInstance() ??? which of these should i use to save the state of my application?? For eg when i press exit button my entire app should exit i have used finish() ? public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); s1=

Android: onDestroy() or similar method in Application class

落爺英雄遲暮 提交于 2019-12-28 04:06:40
问题 I am extending Application class to work with some global variables that need context. I know there is onCreate() method in the Application class that gets called before any other onCreate() in activities, but I would like to know if there is onDestroy() or similar method in the Application class that could be overridden so that I would be able to store variables in persistent memory, unregister listener and send last message to server before app process gets killed? If not, is there any

Interface not reloaded after returning to app from BACK press

走远了吗. 提交于 2019-12-25 08:47:54
问题 I currently have a set of tabs, each tied to a fragment, and I've finally gotten the UI on one of the tabs to look how it should. Here's a screenshot of how the app looks when it has properly loaded (after initial launch and scrolling to a tab): Now, after I hit the back button (I haven't and won't be bothering with a backStack for each tab - I don't like that UI paradigm) and then use app switcher or relaunch from the launcher, my questionRows are gone (they don't reload). Do I need to

how to define the screen orientation before the activity is created?

一世执手 提交于 2019-12-25 05:37:10
问题 I defined my activity to only be in portrait mode by : android:screenOrientation="portrait" When I take a picture with the camera function via intent, take this picture in landscape mode and turn the screen to portrait mode when saving it, i return to my activity again. What I dont understand is, that my activity for a short time is in landscape mode, is destroyed and then built again in portrait mode... as my onCreate ond onRestore functions need some time, the waiting time for the user is

Save Images locally in Image adapter in android

五迷三道 提交于 2019-12-25 02:52:17
问题 This is a question about image saving in android app. I am trying to make popular movies app of an udacity project.Link - https://docs.google.com/document/d/1gtXUu1nzLGWrGfVCD6tEA0YHoYA9UNyT2yByqjJemp8/pub?embedded=true I have picasso library for image downloading in ImageAdapter-- Here is my ImageAdapter code - package jindal5.mayank.popular_movies_14ce10032_gsc; public class ImageAdapter extends BaseAdapter { private String drawablePrefix; private Context mContext; private ArrayList<String>

Android- Why is this happening (“Content not yet created” error)

南楼画角 提交于 2019-12-25 00:45:48
问题 This is a followup to this question: Android - why is this telling me "Content view not yet created"? So, the following code throws an error: public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout Layout5 = (LinearLayout) inflater.inflate(R.layout.tab_frag5_layout, container, false); Cursor allBands; MyDatabase db; Context ctx = (Context)TabFragment5.this.getActivity(); db = new MyDatabase(ctx); allBands = db.getBands(); ListAdapter

Getting a java.lang.IllegalStateException: No activity when resuming an activity

感情迁移 提交于 2019-12-24 12:59:40
问题 I'm getting a weird error in one of my activities. I can't figure out why this is happening. I have an Activity which displays search results to the user. When he taps on one of them, a detailed page for that result is shown, and when he closes that Activity it goes back to the search result screen. It works fine for the most part, except on certain devices where it crashes as soon as the Activity resumes. The stack trace is also useless as it is being thrown internally by the support

Can I create my UI fragment in my activity's onStart()?

∥☆過路亽.° 提交于 2019-12-24 05:59:46
问题 I have an activity with a launchMode of singleTop but I want it to refresh when I go up to it from a child activity. Currently, because my fragment (which contains the UI) is instantiated in the activity's onCreate() , the UI doesn't reload when returning to it. But if I instantiated the fragment in onStart() it would be called when the activity is restarted. While I've gained understanding of the Activity lifecycle, I still don't fully understand how it and the Fragment lifecycle must