unorsk
unorsk

Reputation: 9429

Hide an activity

From my Activity I start an Intent (uploading a picture) and then I wait for result (onActivityResult).

How can I hide my Activity so it could handle the Intents result in a background? moveTaskToBack(true) hides the whole application, but I need just to get back to the previous Activity without finishing the current one.

Upvotes: 1

Views: 4489

Answers (4)

posaidong
posaidong

Reputation: 663

If no view or element in the activity, you can have a try to set the activity as transparent in manifest:

android:theme="@android:style/Theme.Translucent"

Upvotes: 0

Mostafa
Mostafa

Reputation: 28086

As Android documentation explains, Activities are for displaying an interface to the user:

An activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although the activities work together to form a cohesive user experience in the email application, each one is independent of the others. As such, a different application can start any one of these activities (if the email application allows it). For example, a camera application can start the activity in the email application that composes new mail, in order for the user to share a picture.

I recommend reading whole the article.

If you want to do something in background, you can use Thread, AsyncTask, or even a Service. Reading more from this documentation gives you more info about how these kind of things should be handled in Android.

Upvotes: 3

praetorian droid
praetorian droid

Reputation: 3029

I think, short answer is no. You can do it askew, but probably it's not a good interface design. Most likely the user will not happy when your Activity will popped up from background suddenly when he will doing something with te lower Activity.

Specify more precisely, what for do you want to use it. Perhaps there is another way.

Upvotes: 1

Thomas
Thomas

Reputation: 1508

Ideally you want to use AsyncTask here. This allows you to seperate the uploading from the main UI thread, preventing the application from 'not responding'.

Another solution would be to create a new Service. This is not what the documentation recommends though.

Upvotes: 1

Related Questions