I have two activity in my android app. In my second activity i have a button for taking screenshot of...












1















this is what i want I want to capture the screenshot of previous activity while i am on another activity.
if any one help me it will be very helpful for my application and for other also.



public Bitmap getBitmapOFRootView(View v) {

View rootview = v.getRootView();
rootview.setDrawingCacheEnabled(true);
Bitmap bitmap1 = rootview.getDrawingCache();
return bitmap1;

}

public void screenShot(View view) {
Bitmap mbitmap = getBitmapOFRootView(linearlayouttoggle);

// linearlayoutmain.setImageBitmap(mbitmap);

SaveImage(mbitmap);
}


my manifest file



  <activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Toggle"></activity>









share|improve this question




















  • 1





    i think you have to take screenshot first then go to second screen

    – Rohit
    Nov 26 '18 at 8:25






  • 2





    How can you take screenshot of something which is not on the screen ?

    – Vivek Mishra
    Nov 26 '18 at 8:26











  • @Vivek Mishra this is what i want to know from you guys ..

    – farhan
    Nov 26 '18 at 8:31






  • 1





    not possible IMO

    – Vivek Mishra
    Nov 26 '18 at 8:33






  • 1





    @farhan, rohit's suggestion is good one, you already take screenshot and then open next activity.

    – Karan Mer
    Nov 26 '18 at 8:36
















1















this is what i want I want to capture the screenshot of previous activity while i am on another activity.
if any one help me it will be very helpful for my application and for other also.



public Bitmap getBitmapOFRootView(View v) {

View rootview = v.getRootView();
rootview.setDrawingCacheEnabled(true);
Bitmap bitmap1 = rootview.getDrawingCache();
return bitmap1;

}

public void screenShot(View view) {
Bitmap mbitmap = getBitmapOFRootView(linearlayouttoggle);

// linearlayoutmain.setImageBitmap(mbitmap);

SaveImage(mbitmap);
}


my manifest file



  <activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Toggle"></activity>









share|improve this question




















  • 1





    i think you have to take screenshot first then go to second screen

    – Rohit
    Nov 26 '18 at 8:25






  • 2





    How can you take screenshot of something which is not on the screen ?

    – Vivek Mishra
    Nov 26 '18 at 8:26











  • @Vivek Mishra this is what i want to know from you guys ..

    – farhan
    Nov 26 '18 at 8:31






  • 1





    not possible IMO

    – Vivek Mishra
    Nov 26 '18 at 8:33






  • 1





    @farhan, rohit's suggestion is good one, you already take screenshot and then open next activity.

    – Karan Mer
    Nov 26 '18 at 8:36














1












1








1








this is what i want I want to capture the screenshot of previous activity while i am on another activity.
if any one help me it will be very helpful for my application and for other also.



public Bitmap getBitmapOFRootView(View v) {

View rootview = v.getRootView();
rootview.setDrawingCacheEnabled(true);
Bitmap bitmap1 = rootview.getDrawingCache();
return bitmap1;

}

public void screenShot(View view) {
Bitmap mbitmap = getBitmapOFRootView(linearlayouttoggle);

// linearlayoutmain.setImageBitmap(mbitmap);

SaveImage(mbitmap);
}


my manifest file



  <activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Toggle"></activity>









share|improve this question
















this is what i want I want to capture the screenshot of previous activity while i am on another activity.
if any one help me it will be very helpful for my application and for other also.



public Bitmap getBitmapOFRootView(View v) {

View rootview = v.getRootView();
rootview.setDrawingCacheEnabled(true);
Bitmap bitmap1 = rootview.getDrawingCache();
return bitmap1;

}

public void screenShot(View view) {
Bitmap mbitmap = getBitmapOFRootView(linearlayouttoggle);

// linearlayoutmain.setImageBitmap(mbitmap);

SaveImage(mbitmap);
}


my manifest file



  <activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Toggle"></activity>






android screenshot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 13:31







farhan

















asked Nov 26 '18 at 8:18









farhanfarhan

137




137








  • 1





    i think you have to take screenshot first then go to second screen

    – Rohit
    Nov 26 '18 at 8:25






  • 2





    How can you take screenshot of something which is not on the screen ?

    – Vivek Mishra
    Nov 26 '18 at 8:26











  • @Vivek Mishra this is what i want to know from you guys ..

    – farhan
    Nov 26 '18 at 8:31






  • 1





    not possible IMO

    – Vivek Mishra
    Nov 26 '18 at 8:33






  • 1





    @farhan, rohit's suggestion is good one, you already take screenshot and then open next activity.

    – Karan Mer
    Nov 26 '18 at 8:36














  • 1





    i think you have to take screenshot first then go to second screen

    – Rohit
    Nov 26 '18 at 8:25






  • 2





    How can you take screenshot of something which is not on the screen ?

    – Vivek Mishra
    Nov 26 '18 at 8:26











  • @Vivek Mishra this is what i want to know from you guys ..

    – farhan
    Nov 26 '18 at 8:31






  • 1





    not possible IMO

    – Vivek Mishra
    Nov 26 '18 at 8:33






  • 1





    @farhan, rohit's suggestion is good one, you already take screenshot and then open next activity.

    – Karan Mer
    Nov 26 '18 at 8:36








1




1





i think you have to take screenshot first then go to second screen

– Rohit
Nov 26 '18 at 8:25





i think you have to take screenshot first then go to second screen

– Rohit
Nov 26 '18 at 8:25




2




2





How can you take screenshot of something which is not on the screen ?

– Vivek Mishra
Nov 26 '18 at 8:26





How can you take screenshot of something which is not on the screen ?

– Vivek Mishra
Nov 26 '18 at 8:26













@Vivek Mishra this is what i want to know from you guys ..

– farhan
Nov 26 '18 at 8:31





@Vivek Mishra this is what i want to know from you guys ..

– farhan
Nov 26 '18 at 8:31




1




1





not possible IMO

– Vivek Mishra
Nov 26 '18 at 8:33





not possible IMO

– Vivek Mishra
Nov 26 '18 at 8:33




1




1





@farhan, rohit's suggestion is good one, you already take screenshot and then open next activity.

– Karan Mer
Nov 26 '18 at 8:36





@farhan, rohit's suggestion is good one, you already take screenshot and then open next activity.

– Karan Mer
Nov 26 '18 at 8:36












1 Answer
1






active

oldest

votes


















0














NOTE: Assumption is that MainActivity is the first Activity and ToggleActivity is the second Activity (based on comments below)



Your button could go back to the previous Activity and tell it to take a screenshot of itself. In ToggleActivity.onClick() add something like this:



Intent goBackIntent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("screenshot", true);
startActivity(intent);
finish();


Adding the flag FLAG_ACTIVITY_SINGLE_TOP ensures that Android uses the existing instance of the previous Activity and doesn't start a new instance.



In MainActivity you override onNewIntent():



@Override
public void onNewIntent(Intent intent) {
if (intent.hasExtra("screenshot") {
// Add code to take screeenshot here
}
}





share|improve this answer


























  • its not working

    – farhan
    Nov 26 '18 at 11:00











  • i need a bit more info other than 'it is not working'. Please tell me what you did and what is happening. Also add your manifest to your question please (edit the question and paste your manifest in there).

    – David Wasser
    Nov 26 '18 at 12:09











  • @ David Wasser i haved mailed you on your mail id you can check that

    – farhan
    Nov 26 '18 at 12:56











  • @ David Wasser from .Toggle Activity i want to take screenshot of .MainActivity

    – farhan
    Nov 26 '18 at 13:03











  • Sorry, I don't answer Stackoverflow questions in email. Post the data I requested here in the question and maybe I or someone else will help you.

    – David Wasser
    Nov 26 '18 at 13:41












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53477038%2fi-have-two-activity-in-my-android-app-in-my-second-activity-i-have-a-button-for%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









0














NOTE: Assumption is that MainActivity is the first Activity and ToggleActivity is the second Activity (based on comments below)



Your button could go back to the previous Activity and tell it to take a screenshot of itself. In ToggleActivity.onClick() add something like this:



Intent goBackIntent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("screenshot", true);
startActivity(intent);
finish();


Adding the flag FLAG_ACTIVITY_SINGLE_TOP ensures that Android uses the existing instance of the previous Activity and doesn't start a new instance.



In MainActivity you override onNewIntent():



@Override
public void onNewIntent(Intent intent) {
if (intent.hasExtra("screenshot") {
// Add code to take screeenshot here
}
}





share|improve this answer


























  • its not working

    – farhan
    Nov 26 '18 at 11:00











  • i need a bit more info other than 'it is not working'. Please tell me what you did and what is happening. Also add your manifest to your question please (edit the question and paste your manifest in there).

    – David Wasser
    Nov 26 '18 at 12:09











  • @ David Wasser i haved mailed you on your mail id you can check that

    – farhan
    Nov 26 '18 at 12:56











  • @ David Wasser from .Toggle Activity i want to take screenshot of .MainActivity

    – farhan
    Nov 26 '18 at 13:03











  • Sorry, I don't answer Stackoverflow questions in email. Post the data I requested here in the question and maybe I or someone else will help you.

    – David Wasser
    Nov 26 '18 at 13:41
















0














NOTE: Assumption is that MainActivity is the first Activity and ToggleActivity is the second Activity (based on comments below)



Your button could go back to the previous Activity and tell it to take a screenshot of itself. In ToggleActivity.onClick() add something like this:



Intent goBackIntent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("screenshot", true);
startActivity(intent);
finish();


Adding the flag FLAG_ACTIVITY_SINGLE_TOP ensures that Android uses the existing instance of the previous Activity and doesn't start a new instance.



In MainActivity you override onNewIntent():



@Override
public void onNewIntent(Intent intent) {
if (intent.hasExtra("screenshot") {
// Add code to take screeenshot here
}
}





share|improve this answer


























  • its not working

    – farhan
    Nov 26 '18 at 11:00











  • i need a bit more info other than 'it is not working'. Please tell me what you did and what is happening. Also add your manifest to your question please (edit the question and paste your manifest in there).

    – David Wasser
    Nov 26 '18 at 12:09











  • @ David Wasser i haved mailed you on your mail id you can check that

    – farhan
    Nov 26 '18 at 12:56











  • @ David Wasser from .Toggle Activity i want to take screenshot of .MainActivity

    – farhan
    Nov 26 '18 at 13:03











  • Sorry, I don't answer Stackoverflow questions in email. Post the data I requested here in the question and maybe I or someone else will help you.

    – David Wasser
    Nov 26 '18 at 13:41














0












0








0







NOTE: Assumption is that MainActivity is the first Activity and ToggleActivity is the second Activity (based on comments below)



Your button could go back to the previous Activity and tell it to take a screenshot of itself. In ToggleActivity.onClick() add something like this:



Intent goBackIntent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("screenshot", true);
startActivity(intent);
finish();


Adding the flag FLAG_ACTIVITY_SINGLE_TOP ensures that Android uses the existing instance of the previous Activity and doesn't start a new instance.



In MainActivity you override onNewIntent():



@Override
public void onNewIntent(Intent intent) {
if (intent.hasExtra("screenshot") {
// Add code to take screeenshot here
}
}





share|improve this answer















NOTE: Assumption is that MainActivity is the first Activity and ToggleActivity is the second Activity (based on comments below)



Your button could go back to the previous Activity and tell it to take a screenshot of itself. In ToggleActivity.onClick() add something like this:



Intent goBackIntent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("screenshot", true);
startActivity(intent);
finish();


Adding the flag FLAG_ACTIVITY_SINGLE_TOP ensures that Android uses the existing instance of the previous Activity and doesn't start a new instance.



In MainActivity you override onNewIntent():



@Override
public void onNewIntent(Intent intent) {
if (intent.hasExtra("screenshot") {
// Add code to take screeenshot here
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 26 '18 at 13:45

























answered Nov 26 '18 at 8:39









David WasserDavid Wasser

70.2k10143203




70.2k10143203













  • its not working

    – farhan
    Nov 26 '18 at 11:00











  • i need a bit more info other than 'it is not working'. Please tell me what you did and what is happening. Also add your manifest to your question please (edit the question and paste your manifest in there).

    – David Wasser
    Nov 26 '18 at 12:09











  • @ David Wasser i haved mailed you on your mail id you can check that

    – farhan
    Nov 26 '18 at 12:56











  • @ David Wasser from .Toggle Activity i want to take screenshot of .MainActivity

    – farhan
    Nov 26 '18 at 13:03











  • Sorry, I don't answer Stackoverflow questions in email. Post the data I requested here in the question and maybe I or someone else will help you.

    – David Wasser
    Nov 26 '18 at 13:41



















  • its not working

    – farhan
    Nov 26 '18 at 11:00











  • i need a bit more info other than 'it is not working'. Please tell me what you did and what is happening. Also add your manifest to your question please (edit the question and paste your manifest in there).

    – David Wasser
    Nov 26 '18 at 12:09











  • @ David Wasser i haved mailed you on your mail id you can check that

    – farhan
    Nov 26 '18 at 12:56











  • @ David Wasser from .Toggle Activity i want to take screenshot of .MainActivity

    – farhan
    Nov 26 '18 at 13:03











  • Sorry, I don't answer Stackoverflow questions in email. Post the data I requested here in the question and maybe I or someone else will help you.

    – David Wasser
    Nov 26 '18 at 13:41

















its not working

– farhan
Nov 26 '18 at 11:00





its not working

– farhan
Nov 26 '18 at 11:00













i need a bit more info other than 'it is not working'. Please tell me what you did and what is happening. Also add your manifest to your question please (edit the question and paste your manifest in there).

– David Wasser
Nov 26 '18 at 12:09





i need a bit more info other than 'it is not working'. Please tell me what you did and what is happening. Also add your manifest to your question please (edit the question and paste your manifest in there).

– David Wasser
Nov 26 '18 at 12:09













@ David Wasser i haved mailed you on your mail id you can check that

– farhan
Nov 26 '18 at 12:56





@ David Wasser i haved mailed you on your mail id you can check that

– farhan
Nov 26 '18 at 12:56













@ David Wasser from .Toggle Activity i want to take screenshot of .MainActivity

– farhan
Nov 26 '18 at 13:03





@ David Wasser from .Toggle Activity i want to take screenshot of .MainActivity

– farhan
Nov 26 '18 at 13:03













Sorry, I don't answer Stackoverflow questions in email. Post the data I requested here in the question and maybe I or someone else will help you.

– David Wasser
Nov 26 '18 at 13:41





Sorry, I don't answer Stackoverflow questions in email. Post the data I requested here in the question and maybe I or someone else will help you.

– David Wasser
Nov 26 '18 at 13:41




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53477038%2fi-have-two-activity-in-my-android-app-in-my-second-activity-i-have-a-button-for%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen