对于特定的Java代码段,我想测量:
我是一个相对Java的新手,并不熟悉如何实现这一点.我已经被提到了JMX,但是我不确定如何使用JMX,JMX看起来有点"沉重",我正在寻找的东西.
理想情况下,我想要一些可以告诉我想要测量的测量类,可以选择start()在代码段之前调用方法,然后调用stop()方法.相关指标将记录到我指定的文件中.
例如:
import com.example.metricLogger;
metricLogger logger = new metricLogger();
logger.setLogPath(pathToLogFile);
logger.monitor(executionTime);
logger.monitor(memoryUsage);
logger.monitor(cpuLoad);
logger.start();
/* Code to be measured */
logger.stop();
Run Code Online (Sandbox Code Playgroud)
在Java中是否有任何标准/通用/传统方式来实现这一目标?
这种测量用于一次性性能比较,因此我不会寻找任何生产中的长期监测过程.
我很高兴被引用到教程或外部示例,并且不希望在这里得到完整答案.也就是说,如果能够实现上述任何简单的事情,那么一个现实的例子就会非常好.
当有人点击"com.foo.bar://testtest"表单的网页中的链接时,我希望它打开我的统一游戏并让我获取测试数据.
我是一名经验丰富的程序员,但是当涉及到android时,我有点谷歌而不是真正理解任何东西.记住这一点.:)
我可以使用intent-filters对android上的链接做出反应.但是,我发现的所有资源都假设您可以扩展主要活动以捕获新意图.团结可以做到这一点,但出于各种原因,我宁愿不这样做.我尝试创建一个新活动,将其导出到jar,然后将其添加到应用程序标记中的清单:
<activity android:name="com.foo.ProtocolCatcher"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="com.foo.bar" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
点击链接成功启动了我的游戏,但是在黑屏上.
编辑:我也试过这种格式没有改变:
<activity android:name="com.foo.ProtocolCatcher"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="com.foo.bar" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
使整个游戏启动以及我的自定义活动有什么神奇的咒语,让我的自定义活动读取传入的URL,而不触及主要活动?
我有一点问题.我想以其他方式开始活动.我知道
Intent i = new Intent(this, ActivityTwo.class);
Run Code Online (Sandbox Code Playgroud)
初始化意图,之后我可以startActivity.但我想做那样的事情:
Intent i = new Intent(this, MyString.class);
Run Code Online (Sandbox Code Playgroud)
我没有nameActivity.class,但我想在string.class上进行更改.当我有类的字符串名称时,如何启动活动?
我创建了一个 RecyclerView 并在片段中添加了卡片。我想通过单击 CardView 中的不同卡片来打开不同的活动。但我只能为所有卡片打开相同的活动。我在 StackOverFlow 中搜索了不同的答案。但我不能't。你能告诉我如何解决这个问题吗...?如果你能给出完整的代码,我很高兴。
这是我的代码...
PDFFragment.java
public class PDFFragment extends Fragment {
View v;
List<Pdf> listBook;
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
v= inflater.inflate(R.layout.fragment_pdf,container,false);
listBook = new ArrayList<>();
listBook.add(new Pdf("1-pdf name",R.drawable.pdf1image));
listBook.add(new Pdf("2-pdf name",R.drawable.pdf2image));
listBook.add(new Pdf("3-pdf name",R.drawable.pdf3image));
listBook.add(new Pdf("4-pdf name",R.drawable.pdf4image);
listBook.add(new Pdf("5-pdf name",R.drawable.pdf5image));
listBook.add(new Pdf("6-pdf name",R.drawable.pdf6image));
listBook.add(new Pdf("7-pdf name",R.drawable.pdf7image));
RecyclerView myTV= (RecyclerView) v.findViewById(R.id.recyclerview_id);
RecyclerViewAdapterPDF myAdapter = new RecyclerViewAdapterPDF(getActivity(),listBook);
//Part 1 -Start Changing number of columns
myTV.setLayoutManager(new GridLayoutManager(getActivity(),calculateNoOfColumns(getActivity())));
//Part 1 -End Changing …Run Code Online (Sandbox Code Playgroud)