• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps [Networking]Run callback on main thread

I'm developing an app where I need to have a login screen, so users can login.
At the moment I have the login completely working.
The way I'm doing it is as follows
  • The user presses the login button
  • A second thread (Networking thread) is connecting to a webpage with username and password as the post variables
  • The page then checks if the username and password match with a row in my accounts table
  • The page then outputs a 0 (if successful) a 1 (if not successful)
  • The networking thread reads the result and calls a callback with the result
  • The callback then is called on the ui thread of the app and displays a toast if the login wasn't successful or continues to the next activity
Now comes the part where I'm a bit more unsure about, which is the code. To me it feels like overkill to do it this way (especially the part where I put the calling activity as a variable for the callback to execute the callback on the ui thread).

Login method in the login activity
Java:
private void login() {
    Login login = new Login(this);
    login.makeRequest(new Callback<String>() {
        @Override
        public void onComplete(Result<String> result) {
            if (result instanceof Result.Success) {
                Intent dsp = new Intent(LoginActivity.this, MainActivity.class);
                startActivity(dsp);
            } else {
                Result.Error<String> error = (Result.Error<String>) result;
                Toast.makeText(getApplicationContext(), error.message, Toast.LENGTH_SHORT).show();
            }
        }
    }, usernameEt.getText().toString(), passwordEt.getText().toString());
}

makeRequest method in the Login class
Java:
public void makeRequest(final Callback<String> callback, final String username, final String password) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            final Result<String> result = makeSynchronousRequest(username, password);
            callback.execute(result, callingActivity);
        }
    }).start();
}

Callback class
Java:
public abstract class Callback<T> {

    public abstract void onComplete(Result<T> result);

    public void execute(final Result<T> result, AppCompatActivity callingActivity) {
        callingActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                onComplete(result);
            }
        });
    }
}

How to clean Android ....

You describe two differen things.

1) Folders left behind in the user-accessible part of the storage after you uninstall an app. That does happen, and the best answer is to know which of your apps create such folders and delete them manually. But you can use an app like SD Maid, mentioned above, to try to identify orphaned folders like this.

2) App data being back when you restore an app. Are you certain you don't have Google's option to automatically back up such data turned on? Because if you have its' that, rather than the data remaining in your device's storage, that is behind this.

Personally I'm old school: I always use the system Settings to uninstall apps, never the Play Store, and I always clear the app's data manually before uninstalling. That way there is no possibility of anything being left. But as said above, these "private" data are different from the contents of any folders the app may create in the internal storage or on the SD card.

Auto-Enable Loudspeaker On Incoming Calls

Hello Android forums people.

To make it quick, I have been trying to make an app when any device like phone is connected with Bluetooth . then i received the incoming call from anyone then loudspeaker is disabled .but when i am not connected any device from any Bluetooth or other device like that "earphone" then i received incoming call from anyone then loudspeaker is automatically enabled.
I have seen so many posts with different suggestions, but nothing really pinpointing in the right direction.

So.... any ideas on how I can overcome this?

Notification Sound Repeatedly goes off samsung galaxy s8

Had the first day of peace in quite a while. I still don't know for sure if it was the unformatted sd card message that was the source of the notification or if the problem was the repeat notification setting dannydet identified. I believe it was the repeat notification as I don't have an sc card per "my files" (although it is possible the system thought there was a card and thought it wan't formatted. In any event I just wanted to again say thankyou . If anyone has a similar problem in the future I recommend looking at the repeat notification setting. Good job guys, THANKYOU!!

[Free][Game] Mad vs Aliens (by Oliver Bohnes)

<p dir='ltr' style='margin-top:0; margin-bottom:0; text-align:start;'>This is Mad.</p>
<p dir='ltr' style='margin-top:0; margin-bottom:0; text-align:start;'>Mad is a bit paranoid.</p>
<p dir='ltr' style='margin-top:0; margin-bottom:0; text-align:start;'>Mad is afraid of unpleasant surprises.</p>
<p dir='ltr' style='margin-top:0; margin-bottom:0; text-align:start;'>That's why Mad is always well prepared.</p>

<p dir='ltr' style='margin-top:0; margin-bottom:0; text-align:start;'>One day the earth will be threatened.</p>
<p dir='ltr' style='margin-top:0; margin-bottom:0; text-align:start;'>Now Mad is defending the earth against flying aliens.</p>

<p dir='ltr' style='margin-top:0; margin-bottom:0; text-align:start;'>Help Mad defend the earth in 150 levels. Collect coins and improve Mad's attack strength to be prepared against the ever increasing enemies.</p>

<p dir='ltr' style='margin-top:0; margin-bottom:0; text-align:start;'>Enjoy this hand-drawn animated action adventure.</p>

Attachments

  • madvsaliens_01.jpg
    madvsaliens_01.jpg
    194.3 KB · Views: 183
  • madvsaliens_02.jpg
    madvsaliens_02.jpg
    140.4 KB · Views: 160
  • madvsaliens_05.jpg
    madvsaliens_05.jpg
    140.8 KB · Views: 163

Space Oddity: spaceflights calendar, cosmic events, space objects discoveries

Hello,
here you can find another of my apps, about astronomy, space, cosmos etc. I think it's very useful for every astronomy enthusiast. You can check spaceflights schedule, space events in current month, objects discovered this year, comets of the year etc. Feel free to test it, if you have any suggestions than just write them here. Enjoy!

https://play.google.com/store/apps/details?id=pl.ordin.spaceoddity

How to set screen time temporarily without an app?

What devices do you have?

Are they both tied to the same Google account?

What is the purpose of temporary time outs?

As AshS23 eluded to some devices have stuff like this built in but it is impossible for us to tell you what it would be called on your device without knowing what your device is. Samsung has Bixby for instance and the one that AshS23 mentioned. These are usually called assistants but you probably won't find it on the device under that name.

I asked about the shared Google account because I have a recommendation but it is an inexpensive paid app if your device doesn't have an assistant. Tasker is an automated app that you can find at the Play Store that automates actions on Android devices using logic statements. For instance if this temporary timeout is a daily event or a Wednesday event that happens at the same time a profile might look like, Wednesday at 19:00 change screen timeout to 10 minutes. Wednesday at 20:00 change screen timeout to 3 minutes. It can also do things by location, opening an app, date, incoming call, SMS and probably a few that I've forgotten. It's very versatile and can do so many things. Which brings me to my next thing. There are other free automation apps at the Play Store, I don't know those apps so I can't recommend one but many have the same capabilities. Tasker has a forum at Android Central and a Tasker wiki page online where you can turn to for help, I don't think the others do.

Perhaps if we knew more about why you wanted to change your screen timeout we could recommend other things. Why and perhaps the circumstances around the change. For instance if you are just trying to keep it awake longer for a class there might be a better way, easier way, so on and so on.

Help Nexus 6P recharge problem

My Nexus 6P has been such a good phone that I've been willing to deal with any problems, including replacing the battery earlier this year.

Today when I moved it from the car into the house, it would no longer charge, so I swapped wall warts and cables between the car's 500W AC inverter and the house with the same results, even with combinations of both. If the phone is powered down then the charge display lights (71% when powered down), but no additional charge is indicated even after several hours, nor does the charge display go dark after the initial indication..

I doubt that both chargers would fail on the same day, so does this mean that some internal component has failed? Is there anything else to try, please?

Accessories Lunashops: avoid this store

Which adapter did you buy from them? I used to get audio cables from Lunashops many years ago, and it used to take 6wks to get it to US, plus, I have noticed things were getting lost in translation during our communication :) Tbh, when you are dealing with something like BT adapters or other cheap gadgets, better use eBay because of accountability of sellers and money back guarantee. If something doesn't work or breaks within a few weeks, they are willing to send a replacement or offer you another one at discounted price. Otherwise, you buy "as is" since there is no guarantee.

Need rooting help

Your phone may be rootable, however there is little info on it. One thing I want you to verify, is if there is an option saying "Allow OEM unlock" or "autoriser déverrouillage de l'OEM" something like this in the developer options. There is an universal option to unlock the bootloader, using fastboot and magisk patched boot image. You may need to find it on your own. It is possible, just a bit harder. And if you don't understand some "android root" terms, such as fastboot or bootloader unlock and more, then root is not for you.

Filter

Back
Top Bottom