tags:

views:

56

answers:

3

Ive made mis-leading topic in my last question, so i open this new question to clear what I realy want. sorry for the inconvenience.

I wanna run two system(Android) activities one after another in specific order from my main activity.

now as we know, startActivity is an asynchronous operation, so i cant keep on a specific order.

so i thought maybe I should try to do it with dialogBox in the middle but also running a dialogBox is an asynchronous.

now as i said the activities which i try to run are Android activities, so i cant even start them with startActivityForResult (or mybe i can, but i dont get any result back to my main(calling) activity) Any tricks how could i manage with this issue?

Some code:

first activity:

      Intent intent = new Intent(); 
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      intent.setAction(Settings.ACTION_APPLICATION_SETTINGS); 
      startActivity(intent);    

second activity:

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
intent.setDataAndType(Uri.fromFile(tmpPackageFile 
        .getAbsoluteFile()), 
        "application/vnd.android.package-archive"); 
startActivity(intent); 

as you can see, i dont have any access to those activites, i can just run thire intents from my main activity.

A: 

Since you can't have 2 activities running at the same time, start the first, and then start the second once the first returns.

One way of tracking this is to use the startActivityForResult method, it should allow you to control the order the activities are created.

Fredrik Leijon
Ive tried that, it didnt work.. onActivityResult never being invoked in my calling activity.. (mybe coz result never sent back??) !!
rayman
Have you tried without FLAG_ACTIVITY_NEW_TASK? Reading up on the documentation it seems like it might be the issue: http://developer.android.com/guide/topics/fundamentals.html#acttask
Fredrik Leijon
A: 

package com.example.list;

import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener;

public class HelloListView extends ListActivity { protected TextView view;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      String[] countries = getResources().getStringArray(R.array.countries_array);

     setListAdapter(new ArrayAdapter(this, R.layout.list_item, countries));

      ListView lv = getListView();
      lv.setTextFilterEnabled(true);

      lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> ar, View view, int arg2,
                long arg3) {

        switch(arg2)
            {case 0:Intent i1=new Intent(HelloListView.this,ArtistsActivity.class);// list with toast
            startActivity(i1);
            break;

//give different cases and close the switch ,then open a new java file for the next //activity..this opens another list....if u want an activity extend a activity //instead of this listactivity...and register in manifest file

  </activity>

package com.example.list;

import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener;

public class ArtistsActivity extends ListActivity { protected TextView view;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      String[] countries = getResources().getStringArray(R.array.countries_array2);

      setTitle("SUBLIST");

     setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, countries));

      ListView lv = getListView();
      lv.setTextFilterEnabled(true);

      lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                      Toast.LENGTH_SHORT).show();

//this will definetly work if u have basic knowledge.. have given u the code from my app

ankish
A: 

Try this...

Intent intent = new Intent(Settings.ACTION_APPLICATION_SETTINGS); startActivityForResult(intent, 0);

public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == 0) { if (resultCode == RESULT_OK) {

            // start the other activity

        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}
Umesh
thanks, same as answer 1
rayman