Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Java
You last visited: Today at 02:06

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Help] Activity lifecycle Android

Discussion on [Help] Activity lifecycle Android within the Java forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: May 2015
Posts: 8
Received Thanks: 2
[Help] Activity lifecycle Android

Hallo,
ich brauche eure Hilfe.
Ich habe eine App, die Daten aus dem Internet laden soll.
Das soll aber erst passieren, nachdem die Activity sichtbar ist.
Angeblich soll onStart() erst ausgeführt werden, nachdem onCreate() durch ist und die Activity sichtbar ist.
In meinem Fall gibt es aber einen Blackscreen bis onStart() auch durch gelaufen ist, was dazu führt, dass ich bei schlechtem Internet sehr lange im Blackscreen bin. (Ich lade die Sachen in onStart())
Ich würde mich über Hilfe freuen
MrTheAwsomeGuy is offline  
Old 02/09/2018, 16:04   #2
 
elite*gold: 0
Join Date: May 2015
Posts: 700
Received Thanks: 444
Lad es doch im Hintergrund runter, also in einem anderen Thread. Dann ist die UI solange nicht eingefroren.

Hatte mir dazu mal folgendes zusammengereimt, funktioniert, aber keine Ahnung ob es dafür bessere Lösungen gibt.
PHP Code:
public class DefaultPictureService implements PictureService {

    public static final 
String TAG "DefaultPictureService";

    [
MENTION=295804]Override[/MENTION]
    public 
void downloadPicture(LocalPicture localPicturePictureDownloadListener downloadListener) {
        
Log.d(TAG"downloadPicture: " localPicture.getDownloadUrl()
                + 
", width: " localPicture.getWidth()
                + 
", height: " localPicture.getHeight());
        
createDownloadTask(localPicture.getDownloadUrl(), downloadListener).execute();
    }

    [
MENTION=295804]Override[/MENTION]
    public 
void downloadThumbnailPicture(final LocalPicture localPicture, final PictureDownloadListener downloadListener) {
        
Log.d(TAG"downloadThumbnailPicture: " localPicture.getThumbnailDownloadUrl()
                + 
", width: " localPicture.getWidth()
                + 
", height: " localPicture.getHeight());
        
createDownloadTask(localPicture.getThumbnailDownloadUrl(), downloadListener).execute();
    }

    private 
AsyncTask<VoidVoidVoidcreateDownloadTask(final String downloadUrl,
                                               final 
PictureDownloadListener downloadListener) {
        return new 
AsyncTask<VoidVoidVoid>() {
                  [
MENTION=295804]Override[/MENTION]
            protected 
Void doInBackground(Void... params) {
                try {
                    final 
Bitmap bitmap BitmapFactory.decodeStream(new URL(downloadUrl).openStream());
                    new 
Handler(Looper.getMainLooper()).post(new Runnable() {
                              [
MENTION=295804]Override[/MENTION]
                        public 
void run() {
                            
downloadListener.onDownloadFinished(bitmap);
                        }
                    });
                } catch (final 
IOException e) {
                    new 
Handler(Looper.getMainLooper()).post(new Runnable() {
                              [
MENTION=295804]Override[/MENTION]
                        public 
void run() {
                            
downloadListener.onDownloadFailed(e);
                        }
                    });
                }
                return 
null;
            }
        };
    }

algernong is offline  
Thanks
1 User
Old 02/09/2018, 17:46   #3



 
Serraniel's Avatar
 
elite*gold: 0
The Black Market: 205/1/0
Join Date: May 2010
Posts: 6,853
Received Thanks: 5,106
Arrow General Coding -> Java

#moved
Serraniel is offline  
Reply

Tags
activity, android, app, coding, java


Similar Threads Similar Threads
[Android] Update einer Activity mit neuen Widgets
12/07/2014 - General Coding - 2 Replies
Hallo, ich habe vor ein kleines Spiel zu schreiben und stehe vor meinem 1. Problem. Ich möchte (wenn man bspw. den Button "Spiel starten" drückt) meine aktuelle Activity neu laden, allerdings mit neuen Komponenten wie z.B. neuen Buttons, neuen TextViews usw. Ich könnte theoretisch eine neue Activity starten, ist aber nicht Sinn der Sache, weil es nicht unbedingt schön aussieht. Hat jemand eine Idee wie ich das umsetze? Vielen Dank
[S] Android Smartphone großes Display/ Super Amoled (Plus)/ Android 4.0/4.1
04/27/2013 - Smartphones - 6 Replies
Habe mir schon folgende angeschaut : Samsung I9105P Galaxy S II Plus DualCore Smartphone 4,3: Amazon.de: Elektronik und Huawei Ascend P1 Smartphone 4,3 Zoll schwarz: Amazon.de: Elektronik Preisklasse sollte 250€ ca. sein. Macht mir mal Vorschläge :)
Bot für Android|Bot for Android
06/30/2012 - DarkOrbit - 13 Replies
German: Da es nun den DroidBot für Andoid gibt, wollte ich fragen, ob irgend jemand sich mit Android-Programmierung auskennt, und eine Art BoxyBot für Android entwickeln kann. English Since there is now the DroidBot for Andoid, I was just know if anyone is familiar with Android programming, and can develop a kind BoxyBot for Android. Thx Requi



All times are GMT +1. The time now is 02:07.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.