-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathactivity.html
More file actions
100 lines (80 loc) · 4.66 KB
/
Copy pathactivity.html
File metadata and controls
100 lines (80 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Merriweather:300">
<link rel="icon" type="image/png" href="https://android.processing.org/favicon.png">
<link rel="stylesheet" href="../../css/main.css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Processing for Android</title>
</head>
<body>
<nav class="topnav">
<ul class="left">
<li><a href="https://processing.org/">Processing</a></li>
<li><a href="https://p5js.org/">p5.js</a></li>
<li><a href="https://py.processing.org/">Processing.py</a></li>
<li><a href="https://pi.processing.org/">Processing for Pi</a></li>
</ul>
<ul class="foundation">
<li><a href="https://processingfoundation.org/">Processing Foundation</a></li>
</ul>
</nav>
<header>
<h1 class="title">Processing for Android</h1>
</header>
<div class="group">
<nav class="site">
<img class="logo" src="../../imgs/logo_processing_android.svg" alt="Processing for Android logo">
<ul class="leftnav">
<li><a href="../../index.html">Home</a></li>
<li><a href="../../install.html">Install</a></li>
<li><a id="selected" href="../../reference/index.html">Reference</a></li>
<li><a href="../../tutorials/index.html">Tutorials</a></li>
<li><a href="../../books/index.html">Books</a></li>
<li><a href="../../gallery/index.html">Gallery</a></li>
<li><a href="https://discourse.processing.org/c/processing-android" target="_black">Forum</a></li>
<li><a href="https://github.com/processing/processing-android" target="_black">GitHub</a></li>
</ul>
</nav>
<section class="container main-text">
<div class="lang">
<a id="selected" href="activity.html">EN</a>
<a href="../../es/reference/environment/activity.html">ES</a>
</div>
<hr style="clear:both;">
<h2>Getting state of application</h2>
<p>We can obtain a reference to the main <a href="https://developer.android.com/reference/android/app/Activity" target="_black">activity</a> or <a href="https://developer.android.com/reference/android/content/Context" target="_black">context</a> containing the sketch using the getActivity() and getContext() functions:
</p>
<pre><code>
<span style="color: #33997E;">import</span> android.app.Activity;
<span style="color: #33997E;">import</span> android.content.Context;
<span style="color: #33997E;">void</span> <span style="color: #006699;"><b>setup</b></span>() {
Activity activity = getActivity();
}
</code></pre>
<p>The activity will be available only for sketches run as regular or VR apps, since wallpapers and watch faces are services that are not associated to an activity. getContext() should return the context of the application or service in any situation.
</p>
<pre><code>
<span style="color: #33997E;">import</span> android.content.Context;
<span style="color: #33997E;">void</span> <span style="color: #006699;"><b>setup</b></span>() {
Context context = getContext();
}
</code></pre>
<p>When an activity is associated to our sketch, we can also retrive its <a href="https://developer.android.com/reference/android/app/FragmentManager" target="_black">fragment manager</a> and <a href="https://developer.android.com/reference/android/view/Window" target="_black">window</a>:
</p>
<pre><code>
<span style="color: #33997E;">import</span> android.app.FragmentManager;
<span style="color: #33997E;">import</span> android.view.Window;
<span style="color: #33997E;">void</span> <span style="color: #006699;"><b>setup</b></span>() {
FragmentManager manager = getFragmentManager();
Window window = getWindow();
}
</code></pre>
</section>
</div>
<footer class="footinfo">
<small>© The Processing Foundation. Processing for Android is a <a href="../../team.html">collaborative project</a>.</small>
</footer>
</body>
</html>