how can i run code from other android activity
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have two activity, activity 1 and activity 2 . in activity 2 there is something which i want to use from activity 1 button click
protected void onNext() {
AuthType authType = getSelectedAuthType();
if (authType == AuthType.XOAUTH2) {
Globals.getOAuth2TokenProvider().authorizeAPI(mAccount.getEmail(), this,
new OAuth2TokenProvider.OAuth2TokenProviderAuthCallback() {
@Override
public void success() {
updateAccountSettings("");
AccountSetupCheckSettings.actionCheckSettings(
AccountSetupIncoming.this, mAccount, CheckDirection.INCOMING);
}
@Override
public void failure(AuthorizationException e) {
AccountSetupIncoming.this.failure(e);
}
});
return;
}
updateAccountSettings(mPasswordView.getText().toString());
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING);
}
This code is in activity 2 and i want to use this code from activity 1 button click.
I am working on a email application and above code will be use to login with google xoauth2 ,
Bellow is the code from activity 1 which will be use for gmail xoauth if user clicks it will go to activity 2 and use above code
private void onNext() {
if (mOAuth2CheckBox.isChecked()) {
// Auto-setup doesn't support client certificates.
activity2();
return;
}
java android android-activity
add a comment |
I have two activity, activity 1 and activity 2 . in activity 2 there is something which i want to use from activity 1 button click
protected void onNext() {
AuthType authType = getSelectedAuthType();
if (authType == AuthType.XOAUTH2) {
Globals.getOAuth2TokenProvider().authorizeAPI(mAccount.getEmail(), this,
new OAuth2TokenProvider.OAuth2TokenProviderAuthCallback() {
@Override
public void success() {
updateAccountSettings("");
AccountSetupCheckSettings.actionCheckSettings(
AccountSetupIncoming.this, mAccount, CheckDirection.INCOMING);
}
@Override
public void failure(AuthorizationException e) {
AccountSetupIncoming.this.failure(e);
}
});
return;
}
updateAccountSettings(mPasswordView.getText().toString());
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING);
}
This code is in activity 2 and i want to use this code from activity 1 button click.
I am working on a email application and above code will be use to login with google xoauth2 ,
Bellow is the code from activity 1 which will be use for gmail xoauth if user clicks it will go to activity 2 and use above code
private void onNext() {
if (mOAuth2CheckBox.isChecked()) {
// Auto-setup doesn't support client certificates.
activity2();
return;
}
java android android-activity
what do you mean 'This code is in activity 2 and i want to use this code from activity 1 '
– nima_moradi
Jan 4 at 8:14
Then you should extract the common code into its own class and use the same class in both activities.
– EpicPandaForce
Jan 4 at 8:54
@ Epic yes i did the same thing it took a little long but it works :)
– Nitin Dudia
Jan 4 at 10:40
add a comment |
I have two activity, activity 1 and activity 2 . in activity 2 there is something which i want to use from activity 1 button click
protected void onNext() {
AuthType authType = getSelectedAuthType();
if (authType == AuthType.XOAUTH2) {
Globals.getOAuth2TokenProvider().authorizeAPI(mAccount.getEmail(), this,
new OAuth2TokenProvider.OAuth2TokenProviderAuthCallback() {
@Override
public void success() {
updateAccountSettings("");
AccountSetupCheckSettings.actionCheckSettings(
AccountSetupIncoming.this, mAccount, CheckDirection.INCOMING);
}
@Override
public void failure(AuthorizationException e) {
AccountSetupIncoming.this.failure(e);
}
});
return;
}
updateAccountSettings(mPasswordView.getText().toString());
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING);
}
This code is in activity 2 and i want to use this code from activity 1 button click.
I am working on a email application and above code will be use to login with google xoauth2 ,
Bellow is the code from activity 1 which will be use for gmail xoauth if user clicks it will go to activity 2 and use above code
private void onNext() {
if (mOAuth2CheckBox.isChecked()) {
// Auto-setup doesn't support client certificates.
activity2();
return;
}
java android android-activity
I have two activity, activity 1 and activity 2 . in activity 2 there is something which i want to use from activity 1 button click
protected void onNext() {
AuthType authType = getSelectedAuthType();
if (authType == AuthType.XOAUTH2) {
Globals.getOAuth2TokenProvider().authorizeAPI(mAccount.getEmail(), this,
new OAuth2TokenProvider.OAuth2TokenProviderAuthCallback() {
@Override
public void success() {
updateAccountSettings("");
AccountSetupCheckSettings.actionCheckSettings(
AccountSetupIncoming.this, mAccount, CheckDirection.INCOMING);
}
@Override
public void failure(AuthorizationException e) {
AccountSetupIncoming.this.failure(e);
}
});
return;
}
updateAccountSettings(mPasswordView.getText().toString());
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING);
}
This code is in activity 2 and i want to use this code from activity 1 button click.
I am working on a email application and above code will be use to login with google xoauth2 ,
Bellow is the code from activity 1 which will be use for gmail xoauth if user clicks it will go to activity 2 and use above code
private void onNext() {
if (mOAuth2CheckBox.isChecked()) {
// Auto-setup doesn't support client certificates.
activity2();
return;
}
java android android-activity
java android android-activity
edited Jan 4 at 8:28
nima_moradi
499623
499623
asked Jan 4 at 7:54
Nitin DudiaNitin Dudia
16
16
what do you mean 'This code is in activity 2 and i want to use this code from activity 1 '
– nima_moradi
Jan 4 at 8:14
Then you should extract the common code into its own class and use the same class in both activities.
– EpicPandaForce
Jan 4 at 8:54
@ Epic yes i did the same thing it took a little long but it works :)
– Nitin Dudia
Jan 4 at 10:40
add a comment |
what do you mean 'This code is in activity 2 and i want to use this code from activity 1 '
– nima_moradi
Jan 4 at 8:14
Then you should extract the common code into its own class and use the same class in both activities.
– EpicPandaForce
Jan 4 at 8:54
@ Epic yes i did the same thing it took a little long but it works :)
– Nitin Dudia
Jan 4 at 10:40
what do you mean 'This code is in activity 2 and i want to use this code from activity 1 '
– nima_moradi
Jan 4 at 8:14
what do you mean 'This code is in activity 2 and i want to use this code from activity 1 '
– nima_moradi
Jan 4 at 8:14
Then you should extract the common code into its own class and use the same class in both activities.
– EpicPandaForce
Jan 4 at 8:54
Then you should extract the common code into its own class and use the same class in both activities.
– EpicPandaForce
Jan 4 at 8:54
@ Epic yes i did the same thing it took a little long but it works :)
– Nitin Dudia
Jan 4 at 10:40
@ Epic yes i did the same thing it took a little long but it works :)
– Nitin Dudia
Jan 4 at 10:40
add a comment |
1 Answer
1
active
oldest
votes
1:
if you want to jump to the another activity and run the code you mentioned, you can pass a flag in your intent for the second activity.
for example
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtran("EXECUTE_CODE",true);
startActivity(intent);
further in the oncreate of second activity you can check if the flag is true.
bool executeCode = getIntent().getExtras().getBoolean("EXECUTE_CODE");
if(executeCode){
RunCodeYouWantToExecute()
}
2: if you want to get the result back in the firstActivity you can use
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtran("EXECUTE_CODE",true);
startActivityForResults(intent,123)
and in your secondActivity
@Override
public void success() {
updateAccountSettings("");
AccountSetupCheckSettings.actionCheckSettings(
AccountSetupIncoming.this, mAccount,
CheckDirection.INCOMING);
setResults(RESULTS_OK);
finish();
}
and in your firstactivity you can get the result in the activity's overrided method
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent
data)
{
if(requestCode ==123 && resuldCode==RESULT_OK){
//do taks
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54035016%2fhow-can-i-run-code-from-other-android-activity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
1:
if you want to jump to the another activity and run the code you mentioned, you can pass a flag in your intent for the second activity.
for example
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtran("EXECUTE_CODE",true);
startActivity(intent);
further in the oncreate of second activity you can check if the flag is true.
bool executeCode = getIntent().getExtras().getBoolean("EXECUTE_CODE");
if(executeCode){
RunCodeYouWantToExecute()
}
2: if you want to get the result back in the firstActivity you can use
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtran("EXECUTE_CODE",true);
startActivityForResults(intent,123)
and in your secondActivity
@Override
public void success() {
updateAccountSettings("");
AccountSetupCheckSettings.actionCheckSettings(
AccountSetupIncoming.this, mAccount,
CheckDirection.INCOMING);
setResults(RESULTS_OK);
finish();
}
and in your firstactivity you can get the result in the activity's overrided method
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent
data)
{
if(requestCode ==123 && resuldCode==RESULT_OK){
//do taks
}
}
add a comment |
1:
if you want to jump to the another activity and run the code you mentioned, you can pass a flag in your intent for the second activity.
for example
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtran("EXECUTE_CODE",true);
startActivity(intent);
further in the oncreate of second activity you can check if the flag is true.
bool executeCode = getIntent().getExtras().getBoolean("EXECUTE_CODE");
if(executeCode){
RunCodeYouWantToExecute()
}
2: if you want to get the result back in the firstActivity you can use
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtran("EXECUTE_CODE",true);
startActivityForResults(intent,123)
and in your secondActivity
@Override
public void success() {
updateAccountSettings("");
AccountSetupCheckSettings.actionCheckSettings(
AccountSetupIncoming.this, mAccount,
CheckDirection.INCOMING);
setResults(RESULTS_OK);
finish();
}
and in your firstactivity you can get the result in the activity's overrided method
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent
data)
{
if(requestCode ==123 && resuldCode==RESULT_OK){
//do taks
}
}
add a comment |
1:
if you want to jump to the another activity and run the code you mentioned, you can pass a flag in your intent for the second activity.
for example
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtran("EXECUTE_CODE",true);
startActivity(intent);
further in the oncreate of second activity you can check if the flag is true.
bool executeCode = getIntent().getExtras().getBoolean("EXECUTE_CODE");
if(executeCode){
RunCodeYouWantToExecute()
}
2: if you want to get the result back in the firstActivity you can use
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtran("EXECUTE_CODE",true);
startActivityForResults(intent,123)
and in your secondActivity
@Override
public void success() {
updateAccountSettings("");
AccountSetupCheckSettings.actionCheckSettings(
AccountSetupIncoming.this, mAccount,
CheckDirection.INCOMING);
setResults(RESULTS_OK);
finish();
}
and in your firstactivity you can get the result in the activity's overrided method
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent
data)
{
if(requestCode ==123 && resuldCode==RESULT_OK){
//do taks
}
}
1:
if you want to jump to the another activity and run the code you mentioned, you can pass a flag in your intent for the second activity.
for example
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtran("EXECUTE_CODE",true);
startActivity(intent);
further in the oncreate of second activity you can check if the flag is true.
bool executeCode = getIntent().getExtras().getBoolean("EXECUTE_CODE");
if(executeCode){
RunCodeYouWantToExecute()
}
2: if you want to get the result back in the firstActivity you can use
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtran("EXECUTE_CODE",true);
startActivityForResults(intent,123)
and in your secondActivity
@Override
public void success() {
updateAccountSettings("");
AccountSetupCheckSettings.actionCheckSettings(
AccountSetupIncoming.this, mAccount,
CheckDirection.INCOMING);
setResults(RESULTS_OK);
finish();
}
and in your firstactivity you can get the result in the activity's overrided method
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent
data)
{
if(requestCode ==123 && resuldCode==RESULT_OK){
//do taks
}
}
answered Jan 4 at 8:22
Furqan KhanFurqan Khan
143
143
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54035016%2fhow-can-i-run-code-from-other-android-activity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what do you mean 'This code is in activity 2 and i want to use this code from activity 1 '
– nima_moradi
Jan 4 at 8:14
Then you should extract the common code into its own class and use the same class in both activities.
– EpicPandaForce
Jan 4 at 8:54
@ Epic yes i did the same thing it took a little long but it works :)
– Nitin Dudia
Jan 4 at 10:40