android-lifecycle

AsyncTask will always run even if app is destroyed?

两盒软妹~` 提交于 2019-11-29 11:28:48
问题 I have an application and because you can't do network operations on the main thread I'm using AsyncTask , so the question is once I execute() the AsyncTask and right after that I finish() the activity, and maybe the user will finish() the whole app, so what I'm wondering is: Will AsyncTask always finish doInBackground() and onPostExecute() even if the app is closed as long as execute() was called when the app was running? 回答1: You will be able to test this. And yes It does. If execute was

ExoPlayer Restore State when Resumed

妖精的绣舞 提交于 2019-11-29 10:35:16
问题 I have implemented the Player and now there is a problem. When the video is playing and if the app is closed and resumed, the video screen freezes. I even saw the ExoPlayer Demo Activity from Google for better understanding but I could not get through it for implementing in my app. I have attached the Player Activity here and for the full code, I am sharing the GitHub repository for the complete set of files used. RecipeStepDetailFragment.java package com.example.android.recipe.ui; import

android - There is no default constructor for ArrayAdapter

让人想犯罪 __ 提交于 2019-11-29 07:58:49
I m making adapter to adapt my book collection to be visible in list view. Issue is solved if I add super(context, position): public BookAdapter(Context context, int position, List <Book> updatedBooksList) { super(context, position); this.context = context; this.booksList = updatedBooksList ; } However, I want to know why I need this argument (int position) and call superclass constructor? protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Also, in the broader sense why do we always(?) need to call super.onCreate like here in every onCreate? Aren't we

When can onTaskRemoved() be called?

让人想犯罪 __ 提交于 2019-11-29 06:06:32
The docs state that This is called if the service is currently running and the user has removed a task that comes from the service's application. It seems as if it is only called when the app is swiped away from the recent task list. Pressing the back button until all Activities are destroyed in the task does not cause this to be called. Are there other scenarios where this could be called? Pressing the back button until all Activities are destroyed in the task does not cause this to be called. Finishing Activities by pressing the back button doesn't mean that running services and the

Measure view in fragment

此生再无相见时 提交于 2019-11-29 06:02:10
I need to know ImageView width and height. Is there a way to measure it in fragment ? In standard Activity I use this : @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); image.getWidth(); image.getHeight(); } But where can I use image.getWidth(); and image.getHeight(); in fragment ? DeeV Use the GlobalLayoutListener . You assign the listener to your ImageView in onCreateView() just like you do in that answer in the link. It also is more reliable than onWindowFocusChanged() for the main Activity so I recommend switching strategies. EDIT Example

When is the savedInstanceState bundle actually used?

断了今生、忘了曾经 提交于 2019-11-29 01:07:23
Does anyone know of an exhaustive list of when the savedInstanceState bundle will be used in an activity? I know it's used when the device orientation changes. However, it doesn't seem to be used when the user force closes the app from the Android settings, but this might be due to something in my code. What other cases are there? To be clear, by "used" I mean when onCreate() is called, the savedInstanceState bundle is not null and contains the data I passed into it the last time onSaveInstanceState() was called. It's used when the Activity is forcefully terminated by the OS (ex: when your

onCreate being called on Activity A in up navigation

陌路散爱 提交于 2019-11-28 23:33:07
So I have an Activity A and an Activity B. I want Activity A to be able to navigate to Activity B with the press of a button. That works, but when I use the up navigation(the home button in the action bar) to navigate back to Activity A, onCreate() is called again and the old information that the user typed in is lost. I've seen: onCreate always called if navigating back with intent , but they used Fragments, and I'm hoping not to have to redesign the entire app to use fragments. Is there any way I can stop onCreate() from being called every time Activity A becomes active again? This behavior

DialogFrag#show() from a Fragment throwing “IllegalStateException: Can not perform this action after onSaveInstanceState”

爷,独闯天下 提交于 2019-11-28 23:26:52
Just to be clear, I have read the dozen top SO questions on "IllegalStateException: Can not perform this action after onSaveInstanceState" and I have read Alex Lockwood's blog post on the issue http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html So I'm not asking this blindly. I have a very simple use case case that doesn't involve AsyncTask or any background processing. I have a Fragment that contains a button. On the onClickListener for the button, I create a DialogFragment and show it. public final class OverviewFragment extends Fragment { @Override

What is lifecycle for RecyclerView adapter?

大憨熊 提交于 2019-11-28 20:03:24
I'm requesting images from presenter in adapter: @Override public void onBindViewHolder(SiteAdapter.ViewHolder holder, int position) { Site site = sites.get(position); holder.siteName.setText(site.getName()); requestHolderLogo(holder, site.getLinks().getLogoUrl()); } private void requestHolderLogo(final ViewHolder holder, final String logoUrl) { compositeSubscription.add( presenter.bitmap(logoUrl) .subscribe( bitmap -> { holder.siteLogo.setImageBitmap(bitmap); holder.siteLogo.setVisibility(View.VISIBLE); }, error -> { holder.siteName.setVisibility(View.VISIBLE); }) ); } I should unsubscribe

Why is my onResume being called twice?

我的未来我决定 提交于 2019-11-28 19:06:33
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 intent) { Intent newIntent = new Intent(context, MyActivity.class); newIntent.addFlags(Intent.FLAG