Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use putExtra() with FLAG_ACTIVITY_REORDER_TO_FRONT in Android Apps?

Tags:

I have an application, call "App1". In my App1 I invoke Camera application.

intent = new Intent(Intent.ACTION_MAIN); intent.setComponent(new ComponentName("com.android.camera","com.android.camera.Camera")); startActivity(intent); 

After that, I use FileObserver to listen whether user take a photo. When this happens I call

Context ctx = App1.this.getApplicationContext(); Intent j = new Intent(ctx, App1.class); j.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); j.putExtra("type", 1); startActivity(j); 

It works, I mean it gets my application to front how I leave it, however I need to pass an integer, which is called "type". I think, my application will call "onResume()" but how can I get that extra integer. This type of passing didn't do anything in my application.

There's Bundle savedInstanceState in onCreate method, but there is no such a thing in onResume method. So, I need your help to solve this problem. Thanks in advance.

like image 451
Sertalp B. Cay Avatar asked Aug 24 '11 11:08

Sertalp B. Cay


People also ask

How can I get putExtra value in Android?

Using putExtra() and getExtras() in android It has two parameters, first one specifies the name which of the extra data,and the second parameter is the data itself. getExtra() fetches data which was added using putExtra() in the following way: Bundle extras= getIntent(). getExtras();

What is the putExtra () method used with intent for?

Using putExtra() We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.

What is the importance of the putExtra () method in Android how it is different from setData ()?

putExtra allows you to add primitive (or parcelable) key-value pairs. setData is limited to passing an Uri . setData is conventionally used for the case of requesting data from another source, such as in startActivityForResult. but an uri can be sent through putextra also.

How can I pass value from one activity to another activity in Android without intent?

This example demonstrate about How to send data from one activity to another in Android without intent. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

You need to override Activity.onNewIntent() method.

@Override protected void onNewIntent(Intent intent) {     super.onNewIntent(intent);     setIntent(intent); } 

After onNewIntent() is called, the normal onResume() lifecycle will follow. Alternatively, you can write your code in onNewIntent() itself.

like image 186
Gaurav Das Avatar answered Sep 22 '22 04:09

Gaurav Das