Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UART Cant open #8

Open
Ragulmurugan opened this issue Feb 12, 2018 · 6 comments
Open

UART Cant open #8

Ragulmurugan opened this issue Feb 12, 2018 · 6 comments

Comments

@Ragulmurugan
Copy link

E/Exception: UART cant opencom.google.android.things.pio.PioException: android.os.ServiceSpecificException: UART0 is already in use (code 16)

@Fleker
Copy link

Fleker commented Feb 12, 2018

Seems like you've opened it in another activity without closing it. See this Stackoverflow answer to learn more.

@Ragulmurugan
Copy link
Author

But I'm closing UART before passing the Intent in every activity and this problem occurs randomly if it occurs always I can consider I forget to Close somewhere even I had the main thread.sleep before passing the Intent but nothing solved this problem.

@Fleker
Copy link

Fleker commented Feb 15, 2018

Where are you closing it? In the activity's onDestroy method? Do you need to architect your application with multiple activities?

@Ragulmurugan
Copy link
Author

I'm closing it before passing the intent like

            try {
                closeUart();
            } catch (IOException e) {
                Log.e(TAG, "Error closing UART device:", e);
            }
            Intent i = new Intent(MainActivity.this,MainActivity2.class);
            String strName = "j";
            i.putExtra(Intent.EXTRA_TEXT, strName);
            startActivity(i);
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);finish();
            finish();

I'm not closing it in onDestroy method.

@Fleker
Copy link

Fleker commented Feb 16, 2018

Can you add a type of asynchronous wait before starting your activity, like using a Handler:

try {
    closeUart();
} catch (IOException e) {
    Log.e(TAG, "Error closing UART device:", e);
}
h = new Handler(Looper.getMainLooper()) {
    @Override
    public void handleMessage(int what) {
        Intent i = new Intent(MainActivity.this,MainActivity2.class);
        String strName = "j";
        i.putExtra(Intent.EXTRA_TEXT, strName);
        startActivity(i);
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);finish();
        finish();
    }
};
h.sendEmptyMessageDelayed(0, 50);

(this code wasn't tested, so it may not be completely valid)

@Ragulmurugan
Copy link
Author

I have tried using main thread timer before passing the intent. Like
Thread.sleep(1000).
This time I'll try your idea let me use handler .
Thanks dude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants