# Android http get is not working at all

**URL:** <https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944>\
**Category:** ionic-v3\
**Created:** [December 10, 2018, 7:01pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944 "2018-12-10T19:01:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![raresont](https://avatars.discourse-cdn.com/v4/letter/r/b9e5f3/32.png) [@raresont](https://forum.ionicframework.com/u/raresont)\
**Post date:** [December 10, 2018, 7:01pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/1 "2018-12-10T19:01:07Z")

</div>

I have the following piece of code

```
this.http.get(version).pipe(
   map(res => res.json())).subscribe(data => {
     this.storage.ready().then(()=> {

      this.storage.set('version', data);
      currentVersion = 1;
      if(currentVersion < data) {
        this.storage.set('version', data);
        this.http.get(website1).pipe(
          map(res => res.json())).subscribe(data => {
            this.storage.set('website1', data.items);
          });
         this.router.navigateByUrl('/app/tabs/outsideTheLoadingScreen');
      });

 }
);

```

Which works well with ionic serve, I get it working even with cordova in browser, it fails when I try to go back in history, but still loads all the content.

I added access and allow-navigation to the config.xml and also the plugins whitelist and advanced http.  
Does anyone has any clues about this?

Can it be the fact that I use ionic 3 instead of ionic 4?

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [December 10, 2018, 9:29pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/2 "2018-12-10T21:29:46Z")

</div>

When are you reading from storage?

---

<div class="post-metadata">

**Author:** ![raresont](https://avatars.discourse-cdn.com/v4/letter/r/b9e5f3/32.png) [@raresont](https://forum.ionicframework.com/u/raresont)\
**Post date:** [December 10, 2018, 9:35pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/3 "2018-12-10T21:35:27Z")

</div>

After I start the app, I check in ionViewWillEnter()

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [December 10, 2018, 9:37pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/4 "2018-12-10T21:37:09Z")

</div>

So regarding the `storage.set` calls in the code you posted: can you confirm that you are _not_ expecting to be able to read this information until the next time the app has been quit and restarted?

---

<div class="post-metadata">

**Author:** ![raresont](https://avatars.discourse-cdn.com/v4/letter/r/b9e5f3/32.png) [@raresont](https://forum.ionicframework.com/u/raresont)\
**Post date:** [December 10, 2018, 9:40pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/5 "2018-12-10T21:40:33Z")

</div>

For the version variable ,yes, I check it only when the app is started.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [December 10, 2018, 9:42pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/6 "2018-12-10T21:42:36Z")

</div>

OK, then can you be more explicit about what “not working” means? What are you expecting to happen? What actually happens? How are those things different?

---

<div class="post-metadata">

**Author:** ![raresont](https://avatars.discourse-cdn.com/v4/letter/r/b9e5f3/32.png) [@raresont](https://forum.ionicframework.com/u/raresont)\
**Post date:** [December 10, 2018, 9:46pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/7 "2018-12-10T21:46:47Z")

</div>

Sorry if I wasn’t clear from the beginning. The code will check for the version so if this.http.get(version) will not return something then execution of the code will not continue, the version that I get doesn’t matter since the currentVersion \< data always returns true.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [December 10, 2018, 9:49pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/8 "2018-12-10T21:49:03Z")

</div>

I asked three specific questions, and am not seeing an answer to any of them.

What are you expecting to happen?  
What actually happens?  
How are those two different?

---

<div class="post-metadata">

**Author:** ![raresont](https://avatars.discourse-cdn.com/v4/letter/r/b9e5f3/32.png) [@raresont](https://forum.ionicframework.com/u/raresont)\
**Post date:** [December 10, 2018, 9:52pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/9 "2018-12-10T21:52:20Z")

</div>

I expect both http.get to return a promise. If first http.get doesn’t return anything then the app will be stuck into loading screen and that is happening. If the first http.get will return a value then the loading screen will dissapear.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [December 10, 2018, 9:55pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/10 "2018-12-10T21:55:23Z")

</div>

> [@raresont](#):
>
> the app will be stuck into loading screen

I don’t see anything involving loading screens in what you have posted. Can you provide a [minimal complete example](https://stackoverflow.com/help/mcve) that people can use to reproduce your issue?

---

<div class="post-metadata">

**Author:** ![raresont](https://avatars.discourse-cdn.com/v4/letter/r/b9e5f3/32.png) [@raresont](https://forum.ionicframework.com/u/raresont)\
**Post date:** [December 10, 2018, 10:03pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/11 "2018-12-10T22:03:51Z")

</div>

The page where this is executed is considered a loading page, after the http.get returns the promise then \_this.router.navigateByUrl(’/app/tabs/(schedule:schedule)’); is triggered, I updated the code.

I am sure that the problem is from http.get. I compared my code with another project where this works and I didn’t saw my problem, I think that it comes from some settings.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [December 10, 2018, 10:06pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/12 "2018-12-10T22:06:07Z")

</div>

Sorry, but apparently I’m not communicating with you very well, so somebody else is going to have to take over.

---

<div class="post-metadata">

**Author:** ![MarkAurit](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@MarkAurit](https://forum.ionicframework.com/u/MarkAurit)\
**Post date:** [December 15, 2018, 5:57pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/13 "2018-12-15T17:57:16Z")

</div>

Im not going to attempt a specific answer, more some rules of thumb Ive found that work for me:  
if promises are involved, putting logic in the **.then** makes for code that is difficult to debug and maintain. I recommend you refactor it out, along the lines of this sloppy and incomplete pseudo code

```auto
http.get ( .. stuff ..).then(res => {
    this.somename(res);
}, (err) => {
... process error
})

somename(data) {
   if (do some logic) {
       storage.set _// ??? does this return a promise ???_
  }
}

```

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:04pm UTC](https://forum.ionicframework.com/t/android-http-get-is-not-working-at-all/149944/14 "2021-07-19T21:04:02Z")

</div>

Closed on July 19, 2021, 9:04pm UTC


