Android Override methods inside classes with Activity parameter - android

I want to know if I put my activity through other class like this way:
public class GateActivity extends MapActivity {
private Presenter assistant = null;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
assistant = new Presenter(this);
// ...
}
And this other class:
public class Presenter {
private android.app.Activity act;
public Presenter(android.app.Activity a){
this.act = a;
// ...
}
If it's possible in "Presenter" class to create an intent like this:
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
intent.setType("image/*");
act.startActivityForResult(intent, 1);
AND create/handle its "Override onActivityResult(...)" method:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
switch (requestCode){
case 1: // ...
}
Thanks in advance! ;)

Yep, that should work.
When the called activity has completed, GateActivity.onActivityResult() will be called.

Related

How to get data from fragment to parent activity & pass it to back activity?

How flow goes?
Activity 1 -----> Activity 2 (containing/inside) ------> Fragment
WhatI want to achieve?
Fragment (sends some data back to Activity 2) ----> Activity 2 (onBackPressed : collects that data & send it back to Activity 1) ---> Activity 1
How should I achieve above. I really don't want to use any variables/constants to cache the fragment data. Need to know any in-built method to handle this?
Moreover,
Activity 2 loads Fragment inside it.
In onBackPressed, I'm using setResult in Activity 2 to do standard data passing using startActivityForResult from Activity 1.
Also, if I write any method inside Fragment & call from Activity 2 using then due to that to/fro process a WHITE screen appears. So, really don't want to write own method & need to manage it while leaving the Fragment.
You should start Activity2 with startActivityForResult as below;
Intent i = new Intent(this, Activity2.class);
startActivityForResult(i, requestCode);
And in Activity2/fragment, you should finish acitivity as below;
Intent returnIntent = new Intent();
returnIntent.putExtra("result",result);
getActivity().setResult(Activity.RESULT_OK,returnIntent);
getActivity().finish()
And get result in Activity1 as below;
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (this.requestCode == requestCode) {
if(resultCode == Activity.RESULT_OK){
//Get result
}
}
}
Hope it helps.
To pass data from Activity 2 to Activity 1 you can use startActivityForResult() in Activity 1 to start Activity 2, and onActivityResult() in Activity 1 to receive that data.
To pass data from Fragment to Activity 2, I'd suggest to use some interface like
interface OnSomeDataListener {
void onSomeData(SomeData data);
}
Then implement a setter method for this interface to a fragment like
public void setOnSomeDataListener(OnSomeDataListener listener) {
this.listener = listener;
}
And then in Activity, when instantiating a Fragment:
YourFragment fragment = new YourFragment();
fragment.setOnSomeDataListener(new OnSomeDataListener() {
void onSomeData(SomeData data) {
//return the result
Intent intent = new Intent();
intent.putExtra("data", data);
setResult(RESULT_OK, intent);
finish();
}
}
And finally, in the fragment, when you want to return some data to Activity:
if(listener != null) {
listener.onSomeData(dataToReturn);
}
From your FirstActivity call the SecondActivity using startActivityForResult() method
Intent i = new Intent(this, SecondActivity.class);
startActivityForResult(i, 1);
In your SecondActivity set the data which you want to return back to FirstActivity onBackPressed of SecondActivity.
#Override
public void onBackPressed() {
super.onBackPressed();
Intent returnIntent = new Intent();
returnIntent.putExtra("result",result);
returnIntent.putExtra("bool",true);
setResult(Activity.RESULT_OK,returnIntent);
finish();
}
Now in your FirstActivity class write following code for the onActivityResult() method.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if(resultCode == Activity.RESULT_OK){
String result=data.getStringExtra("result");
boolean bool = data.getBooleanExtra("bool");
}
if (resultCode == Activity.RESULT_CANCELED) {
//Write your code if there's no result
}
}
}//
To send data from Fragment to Second activity, you can use interface callback
public interface sendDataListener
{
void sendData(boolean foo);
}
Implement this listener to Second activity
Try to do this:
public class MyFragment extends Fragment{
private MyFragmentCommunicator myFragmentCommunicator;
....
myFragmentCommunicator.sendDataToActivity(name, image, isSend);
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
myFragmentCommunicator = (MyFragmentCommunicator)activity;
}
}
then declare your interface:
public interface MyFragmentCommunicator{
void sendDataToActivity(String name, String image, boolean isSend);
}
and then in your Activity do this:
public class MyActivity extends AppCompatActivity implements MyFragmentCommunicator{
#Override
public void sendDataToActivity(String name, String image, String price) {
//Manipulate the data
}
}
Hope it helps!!!
i acheived in Following way
In Activity write setters and getters
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
and in Fragment
filePath = ((YourActivity) getActivity()).getFilePath();
fileName=((YourActivity) getActivity()).getFileName();
if You are Using Same Fragment in More Than 1 Activity You can Create a constructor for that fragment and Pass context and check context is of which activity
public class BookmarkFragment extends Fragment {
private String filePath;
private String fileName;
Context contextCheckClass;
public BookmarkFragment(Context ctx ) {
this.contextCheckClass=ctx;
}
#SuppressLint("InflateParams")
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
group= (View)inflater.inflate(R.layout.fragment_bookmark, null);
if(contextCheckClass instanceof FirstReaderScreen){
filePath = ((FirstReaderScreen) getActivity()).getFilePath();
fileName=((FirstReaderScreen) getActivity()).getFileName();
// ispurchased=((FirstReaderScreen) getActivity()).isIspurchased();
}
else if(contextCheckClass instanceof MainReaderScreen){
filePath = ((MainReaderScreen) getActivity()).getFilePath();
fileName=((MainReaderScreen) getActivity()).getFileName();
// ispurchased=((MainReaderScreen) getActivity()).isIspurchased();
}
return group;
}
for calling fragment
BookmarkFragment bookmarkFragment=new BookmarkFragment(FirstReaderScreen.this);
getSupportFragmentManager()
.beginTransaction()
.add(R.id.LL_Fragment, bookmarkFragment)//LL_fragment is container
.addToBackStack(null)
.commit();

Android - duplicate "open with" system dialog instance after orientation change

I have simple activity with one button. When button is clicked, I'm firing intent to pick image from gallery. Something strange is going on when I fire intent and then rotate the screen. Here are the steps:
Click button. "Open with" system dialog appears.
Rotate screen. Activity gets recreated, dialog is still shown. Note - I don't call startActivityForResult(Intent, int) again on my activity recreate.
Tap back button. "Open with" dialog disappear, but there is another one beneath it.
So it seems even though I don't call startActivityForResult(Intent, int), new instance of dialog gets created every orientation change, and old instance don't getting destroyed.
Does anyone facing this issue? How to get rid of these duplicate dialogs?
Update 1:
So, here is some sample code:
public class MainActivity extends AppCompatActivity
{
private boolean mIsStarted = false;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null)
{
mIsStarted = savedInstanceState.getBoolean("key");
}
if (!mIsStarted)
{
mIsStarted = true;
Intent intent = new Intent(Intent.ACTION_PICK).setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MimeType.IMAGE);
startActivityForResult(intent, 1);
}
}
#Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putBoolean("key", mIsStarted);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
mIsStarted = false;
}
}
I also tried to set android:configChanges="orientation|keyboardHidden|keyboard|screenSize|mcc|mnc" and still every time I rotate the screen, new copy of dialog (actually this is not a dialog, this is ResolverActivity) being showed on top of previous one. Is this some Android bug or it's just me doing something wrong?
Update 2: so I tried another approach - call finishActivity(int) inside my Activity.onStop(). Result is pretty strange - now I've got only 2 copies of ChooserActivity. After second copy is created, it starts rotating fine.
Here is the code:
public class MainActivity extends AppCompatActivity
{
private static final String LOG_TAG = MainActivity.class.getSimpleName();
#Override
protected void onCreate(Bundle savedInstanceState)
{
Log.d(LOG_TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.make_photo).setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_PICK).setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MimeType.IMAGE);
startActivityForResult(intent, 1);
}
});
}
#Override
protected void onStop()
{
Log.d(LOG_TAG, "onStop");
super.onStop();
finishActivity(1);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Log.d(LOG_TAG, String.format("onActivityResult[requestCode:%d, resultCode:%d, data:%s]",
requestCode, resultCode, data != null ? data.toString() : "NULL"));
}
}
Still wonder why second copy is being created.
Add this to the activity declatation in your androidmanifest.xml
android:configChanges="orientation|screenSize"
This will prevent the activity from getting recreated and resolve the issue of duplicate dialog.
Find out this was silly mistake in my base Activity class. I end up with deriving all my Activities which works with intents from this base IntentProcessingActivity class.
/**
* Base activity for all activities which process intents. This activity saves processing state
* during recreation, so derived activities can get rid of this. This is useful for not showing
* "Open with" dialogs multiple times.
* <p />
* Derived activities can check if some intent is currently processing with {#link
* #isProcessingIntent()} function.
* <p />
* Created by Maksimov Stanislav (s.maks04#gmail.com) on 25.01.16
*/
public class IntentProcessingActivity extends AppCompatActivity
{
private static final String KEY_IS_PROCESSING_INTENT = "IsProcessingIntent";
private boolean mIsProcessingIntent;
#CallSuper
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (savedInstanceState != null)
{
mIsProcessingIntent = savedInstanceState.getBoolean(KEY_IS_PROCESSING_INTENT, false);
}
}
#CallSuper
#Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_IS_PROCESSING_INTENT, mIsProcessingIntent);
}
#CallSuper
#Override
public void startActivityForResult(Intent intent, int requestCode, Bundle options)
{
mIsProcessingIntent = true;
super.startActivityForResult(intent, requestCode, options);
}
#CallSuper
#Override
public void startActivityForResult(Intent intent, int requestCode)
{
mIsProcessingIntent = true;
super.startActivityForResult(intent, requestCode);
}
#CallSuper
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
mIsProcessingIntent = false;
super.onActivityResult(requestCode, resultCode, data);
}
protected final boolean isProcessingIntent()
{
return mIsProcessingIntent;
}
}
On child Activities I just check
if (!isProcessingIntent())
{
startActivityForResult(...);
}

can we call startActivityForResult from adapter?How to get the response?

is it possible to have method startActivtyForResult within an adapter?Then how to get the response? Where to execute the call back function?
Yes, it's possible. You need a reference for the Context in the adapter and call the activity:
Intent intent = new Intent(context, TargetActivity.class);
((Activity) context).startActivityForResult(intent, REQUEST_FOR_ACTIVITY_CODE);
Beware that context must be an activity context or this code will fail.
You get the result in the enclosing activity using onActivityResult as usual.
So, for example:
In your adapter:
MyAdapter(Context context) {
mContext = context;
}
public View getView(int position, View convertView, ViewGroup parent) {
…
open.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
…
Activity origin = (Activity)mContext;
origin.startActivityForResult(new Intent(mContext, SecondActivity.class), requestCode);
}
});
…
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("MyAdapter", "onActivityResult");
}
In your second activity, do as usual with setResult and finish.
In your main activity, capture the result and pass to the adapter callback:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mAdapter.onActivityResult(requestCode, resultCode, data);
}
Yes.You can call startactivityforresult() from adapter.
There are two case-
1.Calling adapter from activity and need onActivityResult in activity.
2.Calling adapter from Fragment and need onActivityResult in fragment.
Case 1:Get OnActivityResult in Activity then pass the reference of activity to adapter constructor
public MyAdapter(Activity pActivity, List<MyBean> pList) {
mList = pList;
mActivity = pActivity;
}
Now startActivityForResult
Intent intent = new Intent(context, TargetActivity.class);
mActivity.startActivityForResult(intent, REQUEST_FOR_ACTIVITY_CODE);
Case 2: Get OnActivityResult in Fragment then pass the reference of fragment to adapter constructor
public MyGamesAdapter(Fragment pContext, List<MyBean> pList,) {
mList = pList;
mMyFragment =pContext;
}
Intent intent = new Intent(context, TargetActivity.class);
mMyFragment.startActivityForResult(intent, REQUEST_FOR_ACTIVITY_CODE);
Now in activity or fragment override OnActivityResult and get result.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mAdapter.onActivityResult(requestCode, resultCode, data);
}
I used a simpler method. create a public function in you activity/fragment which will call activity for result
public void startActivityFromAdapter(String Arguments){
//todo: add steps you would like to compute
startActivityForResult(Intent, REQ_CODE);
}
When creating the adapter, pass the current activity/fragment as an argument. I will use activity for example
public MyAdaper(Activity activity, ArrayList<String> list){
this.activity = activity;
this.list = list;
}
call the public function from viewholder by casting the activity to the Activity Class
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.applyBt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
((ActivityName) activity).startActivityFromAdapter(list.get(position).code);
}
});
}
and use onActivityResult in your calling activity/fragment
Edit:
I would not recommend using above method as it limits the adapter to be used in only one activity. Better you must use an interface for the same
create an interface and a onClickFunction
public interface AdapterInteface{
void onBtClick(int Position)
}
now when you create the adapter, accept this interface as an argument and call the function when button is clicked
public MyAdaper(Activity activity, ArrayList<String> list, AdapterInterface adapterInterface){
this.activity = activity;
this.list = list;
this.adapterInterface = adapterInterface
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.applyBt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
adapterInterface.onBtClicked(position)
}
});
}
Implement this interface on your activity/fragment and override the function onBtClicked on your activity/fragment to startActivityForResult
write a functon in activity class like this
public void startCommentActivity(Intent i){
startActivityForResult(i, 100);
}
call it in adapter class
mActivity.startCommentActivity(intent);
The androidX Activity implementation has a new set of APIs to get an activity result anywhere you wish.
This functionality replaces the old startActivityForResult() / onActivityResult() and onRequestPermissionsResult(), which have been deprecated in the ComponentActivity.
Example starting a second activity and expecting a result from it:
final Intent intent = new Intent(context, SecondActivity.class);
final ActivityResultContracts.StartActivityForResult contract = new ActivityResultContracts.StartActivityForResult();
activity.registerForActivityResult(contract, result ->
YourClass.manageTheResult(result))
.launch(intent);
Example requesting user permissions:
final String[] permissions = {Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO};
final ActivityResultContracts.RequestMultiplePermissions contract = new ActivityResultContracts.RequestMultiplePermissions();
activity.registerForActivityResult(contract, result -> {
YourClass.manageTheResult(permissions, result);
}).launch(permissions);
Example managing a "sender intent":
final IntentSenderRequest request = new IntentSenderRequest.Builder(yourIntentSender)
.build();
final ActivityResultContracts.StartIntentSenderForResult contract = new ActivityResultContracts.StartIntentSenderForResult();
activity.registerForActivityResult(contract, result ->
YourClasss.manageTheResult(result))
.launch(request);

How to call startactivityforresult from a non-activity class to get the resuts

Is it possible to call startActivityForResult() from a non-activity class to get the results?
Scenario is something like this:
I have a class NonActivity (it doesn't derive from Activity as its not a UI).
This class will have bunch of functions(steps basically) to run.
One of the steps requires to show UI(Activity) and then get the result (user enter something).
Then been able to use that data in next following steps.
How can this be achieved without deriving from activity class as I don't have UI component?
Also since I don't want to derive from activity class that means I cannot override OnActivityResult(). Where results actually come from?
startActivityForResult() is only available from real on-screen activities, since it is a method in, well, Activity. Please redesign your application so that the user interface is driven from activities.
On the other hand, if your non Activity class is initialized and used from an onscreen Activity, you could pass that instance of the Activity to your class as a parameter in the constructor and use it to launch other Activities.
Be careful though. Using this method increases the risk of a memory leak, as the external class (Utils in my example) might keep a reference to the Activity even after its gone.
If all you want to do is access data, then you could try writing it to SharedPreferences or a Database or some files and then using the application context (passed in via a constructor again) to read it. This reduces the risk of a memory leak. Something like:
MyApiClass myApiClass = new MyApiClass(getApplicationContext());
EXAMPLE CODE
Main Activity:
public class Main extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils util = new Utils(this);
util.startTest();
}
#Override
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
Toast.makeText(this, "onActivityResult called", Toast.LENGTH_LONG).show();
super.onActivityResult(arg0, arg1, arg2);
}
}
Utils class (which launches for result):
public class Utils {
Activity activity;
public Utils(Activity ac) {
activity = ac;
}
public void startTest() {
Intent i = new Intent(activity, Test.class);
activity.startActivityForResult(i, 1);
}
}
Test Activity:
public class Test extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(this, "Test", Toast.LENGTH_LONG).show();
this.setResult(Activity.RESULT_OK);
this.finish();
}
}
StartActivityForResult from a class using a fragment with no visible GUI. You might find something like this in a utility class.
see runGetUserAccount below. It creates its own fragment and executes a startActivityForResult. Then it has it's own onActivityResult.
public class MyGooglePlay {
private static final int CONNECTION_FAILURE_RESOLUTION_REQUEST = 31502;
private ActionBarActivity activity;
private FragmentManager fragManager;
public MyGooglePlay(ActionBarActivity activity) {
this.activity = activity;
this.fragManager = activity.getSupportFragmentManager();
}
/**
* Starts an activity in Google Play Services so the user can pick an
* account
*/
private String mEmail = "";
static final int REQUEST_CODE_PICK_ACCOUNT = 1000;
public void runGetUserAccount() {
if (TextUtils.isEmpty(mEmail)) {
// run this code in gui less fragment so we can pickup the
// on activity result from inside the mygoogleplay class.
Fragment f = new Fragment() {
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
String[] accountTypes = new String[] { "com.google" };
Intent intent = AccountPicker.newChooseAccountIntent(null,
null, accountTypes, false, null, null, null, null);
startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
}
#Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
if (resultCode == Activity.RESULT_OK) {
set_Email(data
.getStringExtra(AccountManager.KEY_ACCOUNT_NAME));
// getUsername();
}
super.onActivityResult(requestCode, resultCode, data);
}
//this is to verify the fragment has been removed.
//you can log or put a breakpoint to verify
#Override public void onDestroy(){
super.onDestroy();
}
};
FragmentTransaction fragmentTransaction = this.fragManager
.beginTransaction();
fragmentTransaction.add(f, "getusername");
fragmentTransaction.commit();
}
}
/**
* #param mEmail
* the mEmail to set
*/
private void set_Email(String mEmail) {
this.mEmail = mEmail;
if (!TextUtils.isEmpty(mEmail)) {
// TODO notify caller email is ready;
// activity.onEmailReady(mEmail);
}
//we are done with the "getusername" fragment
Fragment f = fragManager.findFragmentByTag("getusername");
if (f!=null) {
fragManager.beginTransaction().remove(f).commit();
}
}
}
U should pass context as Activity,then u will get solution.
try this below code.it will work
In non Activity class
public class nonActivity {
public static void method(Activity activity)
{
Intent intent = new Intent(activity, SecondActivity.class);
activity. startActivityForResult(intent, REQUEST_CODE);
}
}
In SecondActivity
Intent intent = getIntent();
intent.putExtra("data", "data"); //here u can pass data to previous activity
setResult(RESULT_OK, intent);
finish();
In firstActivity
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
try {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
String status = data.getStringExtra("data");
//Do what u want with data
}
} catch (Exception e) {
System.out.println("=====Exception=====" + e.toString());
}
}
If you want the result back from the activity to your normal class, supposed it is a class with a custom adapter within it.
you cannot use startActivityForResult because you are not in an activity
what I did is that i launched the activity from the class with an intent. Then I calculated or did what I have to. From this activity I send the information to the main class supposed with a method MainActivity.the_method() and in the main activity I changed the custom adapter o did what I have to using the adapter object and calling adapter.getItem(position)
Hope this can give you an idea

onActivityResult not called from main class

I have a problem with my application.I have an activity called ExperimentView which has an inner class called FrameRoll which implements Runnable.
public class ExperimentView extends Activity implements OnClickListener,{
public void onCreate(Bundle savedInstanceState) {
//Other stuff
//Call the gpshandler activity
gpsCall();
}
public void gpsCall() {
if (gpsEnabled.equalsIgnoreCase("true")) {
Intent gpsHandler = new Intent(ExperimentView.this,
GpsHandler.class);
startActivityForResult(gpsHandler,
GPSHANDLER_ACTIVITY_RETURN);
finish();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//retrieve the data
}
public class FrameRoll implements Runnable {
//do other stuff
}
}
I'm calling a subactivity from the onCreate method in order to retrieve some gps data.The gps data are retrieved successfully.
public class GpsHandler extends Activity {
//obtain location
enter code here
Intent resultIntent = new Intent();
resultIntent.putExtra("location",
optimalLocation.toString());
setResult(Activity.RESULT_OK, resultIntent);
}
When i try to call the subactivity from the inner class (frameroll) the sub activity runs normally but the method onActivityResult in ExperimentVIew is never called,so i don't get any data back.
public class ExperimentView extends Activity implements OnClickListener,{
public void onCreate(Bundle savedInstanceState) {
//Other stuff
//Call the gpshandler activity
gpsCall();
}
public void gpsCall() {
if (gpsEnabled.equalsIgnoreCase("true")) {
Intent gpsHandler = new Intent(ExperimentView.this,
GpsHandler.class);
startActivityForResult(gpsHandler,
GPSHANDLER_ACTIVITY_RETURN);
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//retrieve the data
}
public class FrameRoll implements Runnable {
gpsCall();
}
}
I've tried different stuff which included implementing onActivityResult in the nested class,trying to do something like ExperimentView.this.startActivityForResults(),I printed the callingActivity in the gpshandler and it was the ExperimentView.
Every method i tried just failed.The onActivityResult is called only when the subactivity was called from onCreate.Does anynone know what should i do?
Thanx :)
onActivityResult is called once your called-activity is finished. Therefore, you need to call finish(); after setting result. For example:
setResult(Activity.RESULT_OK, resultIntent);
finish();
*Make sure you are GpsHandler class complies with the correct implementation of Activity as it doesn't seem to override onCreate and/or other methods.

Categories

Resources